structure function returns -- how?

Robert Firth firth at sei.cmu.edu
Tue Jan 6 01:11:48 AEST 1987


In article <326 at bms-at.UUCP> stuart at bms-at.UUCP (Stuart D. Gathman) writes:
>*** The real solution ***
>
>(f)	For an assignment, the caller passes a pointer to the object
>	being assigned.  The function does the copy.
>
>P.S. 	This idea is free provided that the user implements it
>on our compilers or else hires me to implement it on their compiler. :-)
>-- 
>Stuart D. Gathman	<..!seismo!dgis!bms-at!stuart>

Sorry.  This fails if the called function accesses the destination
object via another path.  Consider for instance

Z1 : COMPLEX;

Z1 := SWAP_RE_AND_IM(Z1);

with parameter and result object implemented by reference.

The code of the SWAP has

	return COMPLEX'(ARG.IM,ARG.RE);

If the result is assigned piecemeal to the result place,
then Z1.RE will have been overwritten.  This is clearly a
compiler bug, since nearly all languages specify that the
RHS shall be completely evaluated BEFORE the assignment is
performed, and the error arises because the implementation
violates those semantics.



More information about the Comp.lang.c mailing list