structure function returns -- how?

Michael Meissner meissner at dg_rtp.UUCP
Fri Jan 2 05:16:31 AEST 1987


In article <5076 at ism780c.UUCP> tim at ism780c.UUCP (Tim Smith) writes:
>
>If the called function does the copying, then the following can
>cause problems:
>        struct SpanishInquisition nobody, expected();
>
>        nobody = expected();
>        expected();
>
>How does expected() tell these two cases apart?  If it doesn't, then
>it is going to blow away something when it tries to copy back a structure
>in the second call.
>
>I suppose the compiler could note that the return value is being ignored,
>and pass a pointer to some temporary place to hold the ignored return
>value, but that seems kind of ugly.

If the compiler returns structures by having the caller pass a pointer to
an area that is copied into, then for the second example, the compiler does
have to create a temporary (preferably a stack temp...) and pass it's pointer.
If it doesn't, the compiler has an undocumented feature (ie, bug) and it
should be fixed.  BTW, the Data General compiler does return structures in
this manner, and yes we do pass the address of a temporary in an accumulator.
-- 
	Michael Meissner, Data General
	...mcnc!rti-sel!dg_rtp!meissner



More information about the Comp.lang.c mailing list