Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!seismo!rochester!pt.cs.cmu.edu!sei.cmu.edu!firth
From: firth@sei.cmu.edu (Robert Firth)
Newsgroups: comp.lang.c
Subject: Re: structure function returns -- how?
Message-ID: <505@aw.sei.cmu.edu.sei.cmu.edu>
Date: Mon, 5-Jan-87 10:11:48 EST
Article-I.D.: aw.505
Posted: Mon Jan  5 10:11:48 1987
Date-Received: Mon, 5-Jan-87 21:44:14 EST
References: <131@hcx1.UUCP> <773@maynard.BSW.COM> <7403@utzoo.UUCP> <490@aw.sei.cmu.edu.sei.cmu.edu> <326@bms-at.UUCP>
Sender: netnews@sei.cmu.edu
Reply-To: firth@bd.sei.cmu.edu.UUCP (PUT YOUR NAME HERE)
Organization: Carnegie-Mellon University, SEI, Pgh, Pa
Lines: 30

In article <326@bms-at.UUCP> stuart@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.