Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Re: pointers... (http://www.velocityreviews.com/forums/t313796-re-pointers.html)

Simon Biber 06-25-2003 02:47 AM

Re: pointers...
 
"geo" <geometrikal@hhoottmmaaiill> wrote:
> and then i had a function which used this structure. What
> is the best programming practice:
>
> void function(struct random_struct * r) {
> .......
> }
>
> function(&random);
>
> or:
>
> void function(struct random_struct r) {
> .......
> }
>
> function(random);


There is no 'best programming practice'. They do very
different things. Use the former when you want to modify
the existing copy of the struct in place, and use the
latter when you want to have a fresh copy that you can
modify, without changing the original.

If you don't want to modify it at all, the function
should take a pointer to const struct random_struct.

--
Simon.
--
comp.lang.c.moderated - moderation address: clcm@plethora.net


All times are GMT. The time now is 04:17 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.