Address of array; really structure & [array] passing
Peter S. Shenkin
peters at cubsvax.UUCP
Sat Apr 5 05:12:48 AEST 1986
A naive question. When a structure containing many objects, some of which
may be arrays, is passed, doesn't everything in it have to be copied at
execution time, so that manipulations of the contents of the passed parameter
within the called function don't affect the copy in the calling function?
Wouldn't this also have to occur if arrays could be passed by value?
If the structures/arrays are large, doesn't this incur a large overhead?
That is, it seems to be a tradeoff between programming ease and syntactical
elegance, on the one hand, versus time as well as space, on the other.
I'm not trying to make a general argument against pass-by-value for structures
[or arrays], but isn't the practice best avoided when large structures may
be expected? I'm thinking not only of cases when the arrays contained
within a structure are known to be large, but when space for them is
dynamically allocated; then you might end up building larger objects than
you had anticipated when you wrote the program.
On rereading this, perhaps I'm wrong; if I declare
struct { float array[MANY]; } sarray;
and call
result = func(sarray);
are all the elements of sarray.array passed to func(), or is just the
address of the array copied when the structure is passed? Enlighten me!
Peter S. Shenkin Columbia Univ. Biology Dept., NY, NY 10027
{philabs,rna}!cubsvax!peters cubsvax!peters at columbia.ARPA
More information about the Comp.lang.c
mailing list