Why pass structs? (not struct pointers)
cramer at kontron.UUCP
cramer at kontron.UUCP
Wed Mar 4 12:51:19 AEST 1987
> I have been aware of the post V7 C compilers passing and
> returning structs from procedures, and I am curious as to
> why.
>
> Passing structures as a whole seems to violate my impression
> of the nature of C. I feel that a good reason for passing
> arrays by reference (yes, I know that the pointer is passed by
> value :-) is to save an enormous ammount of stack and CPU time.
>
> To pass a structure by value seems to require an arbitrarily
> large amount of stack; but more importantly, non-atomic
> stack operations. That is, that I can push a long, int, char
> or any pointer with (hopefully) one machine-op. To pass
> a structure would require a number of pushes, a block-copy-op,
> or some looping copy code.
>
> I imagine that the people who added this to C had good reason,
> so could someone please tell me what I am missing or have
> gotten wrong?
>
> matt wartell
One reason I have for occasionally passing a structure, rather than a
pointer to the structure, is if the structure is purely an input, and
I want to make sure that the called function doesn't alter the caller's
copy of the structure.
Clayton E. Cramer
More information about the Comp.lang.c
mailing list