Why pass structs? (not struct pointers)
ron at brl-sem.UUCP
ron at brl-sem.UUCP
Sat Feb 28 04:54:52 AEST 1987
In article <3346 at cisunx.UUCP>, ed360463 at cisunx.UUCP (wartell m) writes:
>
> 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.
Well your hopes are wrong. There are many machines that can not
push anything on the stack in one operation. Even more enlighted
machines with autodecrement indexed stack pointers or push instructions
can't push the larger datatypes on the stack with one instruction.
I'm not sure what point you are trying to make. There is a lot of
stuff in the subroutine call sequence that is a lot more vulnerable
to interruption than a single argument push.
> 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?
Mostly because it seemed that it would be silly not to. You can
push and return any other data type (well almost any other, unions
still don't work mostly). The only reason STRUCTS were initially
left out was because they weren't easy to do.
-Ron
More information about the Comp.lang.c
mailing list