"Thomas Matthews" <> wrote:
> The first function is preferred. Structures may become very
> huge, and moving them around costs a lot processor power (not
> to mention space to hold all the temporary copies).
>
> Passing a pointer to a structure is the preferred method. The
> structure can remain in one place while pointers to it are
> passed around. The idea is that a pointer takes up less space
> than a structure. By keeping the structure in one place in
> memory, the overhead of copying it is removed which lowers the
> execution load on the processor (and reduces the memory
> requirements).
If this is your reason for preferring the first function, then I
wholeheartedly disagree.
The only case where your argument applies is if the function
will not be making any changes to the struct. In that case,
neither of the functions is correct, as they should instead
use a pointer to const.
These two functions are only of use when you intend to modify
the struct within the function. In that case your argument is
completely invalid, as they have very different semantics --
the first will change the original in the caller, whereas the
second makes a copy of the struct so can be used as scratch
without affecting the caller's copy. The decision must be made
based on which one of these two behaviours is required.
--
Simon.
--
comp.lang.c.moderated - moderation address: