![]() |
Re: pointers...
In comp.lang.c.moderated geo <geometrikal@hhoottmmaaiill> wrote:
[...] > What is the best programming practice: > void function(struct random_struct * r) { > ....... > } > or: > void function(struct random_struct r) { > ....... > } As with all good "either ... or" questions, the answer is either "it depends", or "none of these". These two ways of of passing a struct to a function differ not only in "programming practice", but also in their actual effect. The first will let changes to *r done inside the function propagate to the calling function, the second won't. If that's not what the function is supposed to be doing, be sure to qualify the struct as 'const': void function (const struct random_struct * const p){ /* ... */ } thereby making both the pointer itself and the struct it points to read-only for function(). That settled, the remaining issue is indeed one of good practice, but still the answer is "it depends". To be precise, it depends on the size of the struct, and the platform this will be used on, whether you can afford passing a copy of the struct instead of just the pointer. -- Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de) Even if all the snow were burnt, ashes would remain. -- comp.lang.c.moderated - moderation address: clcm@plethora.net |
| All times are GMT. The time now is 12:29 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.