Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site utcsri.UUCP Path: utzoo!utcsri!greg From: greg@utcsri.UUCP (Gregory Smith) Newsgroups: net.lang Subject: Re: Re: Multiple assignments Message-ID: <2883@utcsri.UUCP> Date: Sun, 1-Jun-86 12:55:39 EDT Article-I.D.: utcsri.2883 Posted: Sun Jun 1 12:55:39 1986 Date-Received: Sun, 1-Jun-86 13:32:31 EDT References: <1455@mmintl.UUCP> <825@bentley.UUCP> <1482@mmintl.UUCP> <201@cdx39.UUCP> <2846@utcsri.UUCP> <1516@mmintl.UUCP> Reply-To: greg@utcsri.UUCP (Gregory Smith) Organization: CSRI, University of Toronto Lines: 48 Summary: In article <1516@mmintl.UUCP> franka@mmintl.UUCP (Frank Adams) writes: >In article <2846@utcsri.UUCP> greg@utcsri.UUCP (Gregory Smith) writes: >>It becomes the same as >> x = 0; >> y = x; /* actually y=(double)x */ >> >>Are you suggesting that given (x,y)=0; it will be easier for a compiler >>to detect the incompatibility and generate >> x = 0; >> y = 0.0; ???? >>I don't really think so. > >Yes, because "(x,y)=0;" is equivalent to "x=0; y=0;", unlike "x=y=0", which >as you note is equivalent to "y=0; x=y;". 'Equivalent' in both cases meaning 'yielding the same result' and not nec. 'implemented as'. ( I'm sure you meant that too ). > >On the flip side, a naive compiler will generate less efficient code for >something like: > > int i, j; > float a; > (i,j)=a; > >than it would when the last line is "i=j=a"; it will do the float to int >conversion twice. It would screw up because it would compile i=a;j=a;. But what about (i,j) =array[ func(foo-bar)+i]*17? If a compiler treated *that* as two statements, it would be more than just naive. So the code generator would have to take a look at the RHS to see if splitting the assignment in two is a good idea or not. My point is that the same decision can be made with the C format of i=j=... So the problem is not inherent in 'i=j=' - the problem is that few ( if any ) compilers go to this trouble. I will admit that the semantics of i=j= can get funny when i and j are of different types -especially when j is fewer bits than j. > >Frank Adams ihnp4!philabs!pwa-b!mmintl!franka -- "We demand rigidly defined areas of doubt and uncertainty!" - Vroomfondel ---------------------------------------------------------------------- Greg Smith University of Toronto UUCP: ..utzoo!utcsri!greg