Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!seismo!rutgers!clyde!cuae2!ltuxa!ttrdc!levy
From: levy@ttrdc.UUCP (Daniel R. Levy)
Newsgroups: comp.lang.c
Subject: Re: structure function returns -- how?
Message-ID: <1438@ttrdc.UUCP>
Date: Sun, 11-Jan-87 16:35:12 EST
Article-I.D.: ttrdc.1438
Posted: Sun Jan 11 16:35:12 1987
Date-Received: Mon, 12-Jan-87 06:35:39 EST
References: <131@hcx1.UUCP> <773@maynard.BSW.COM>
Organization: AT&T, Computer Systems Division, Skokie, IL
Lines: 34

In article <505@aw.sei.cmu.edu.sei.cmu.edu>, firth@sei.cmu.edu.UUCP writes:
>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.
>>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.

This "failure" can only happen if the arguments are passed by reference,
as well as the destination.  If they are passed by value, or if the ap-
parent passing of struct arguments by value is really implemented by passing
them by reference but the called routine (with struct-valued return value)
is "smart" enough to use copies in cases of overlap instead of the originals,
you avoid this problem.
-- 
 -------------------------------    Disclaimer:  The views contained herein are
|            dan levy            |  my own and are not at all those of my em-
|         an engihacker @        |  ployer or the administrator of any computer
| at&t computer systems division |  upon which I may hack.
|        skokie, illinois        |
 --------------------------------   Path: ..!{akgua,homxb,ihnp4,ltuxa,mvuxa,
                                        allegra,ulysses,vax135}!ttrdc!levy