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/t313799-re-pointers.html)

goose 06-25-2003 02:48 AM

Re: pointers...
 
"geo" <geometrikal@hhoottmmaaiill> wrote in message news:<clcm-20030623-0001@plethora.net>...
> hi all
>
> say if i had :
>
> struct random_struct {
> .....
> .....
> .....
> }
>
> struct random_struct random;
>
> 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);
>


it would depend mostly on what your function is supposed to
do with the structure.

usually, it is "better" in terms of efficiency to pass a pointer
to the structure, but that allows the function to modify the
contents of the structure.

if the function *has* to make modifications to the contents of
the structure, then you can only pass a pointer. if the function
*must not* make changes to the structure contents, then you
can either
a) pass the entire structure as an argument.
b) pass a pointer with necessary const-ness.

hth
goose,
not too sure about the const-ness bit
--
comp.lang.c.moderated - moderation address: clcm@plethora.net


All times are GMT. The time now is 08:44 AM.

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


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57