![]() |
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.