fleming@uncw.UUCP (Chris Fleming) (08/10/90)
Is this how it is always done? Say we have a, b, and c all ints. a=b=c=0; Is this always: Or would someone really implement as: c=0; a=0; b=0; b=0; a=0; c=0; ? ? I ran some test with TC++ 1.0 and feel confident that it is done the "always" way rather than the "other" way. How about from the compiler writers point of view....is there a difference? Linked lists come to mind....without knowing for sure, do I say: l=l->l_next=new l_list('a',l); // Just an example or do I say: l->l_next=l=new l_list('a',l); I know the safe method: l->l_next=new l_list('a',l); l=l->l_next; Should work no matter, but..........isn't there a standard? --------------------------------------------------------------------- Chris Fleming University of NC at Wilmington {...,mcnc}!ecsvax!uncw!fleming fleming@ecsvax!uncw
psrc@mtunq.ATT.COM (Paul S. R. Chisholm) (08/10/90)
In article <857@uncw.UUCP> fleming@uncw.UUCP (Chris Fleming) writes: >a=b=c=0; >Is this always: >c=0; b=0; a=0; >Or would someone really implement as: >a=0; b=0; c=0; The assignment operator is right associative, even when overridden. a = b = c = 0 is equivalent to a = ( b = ( c = 0 ) ) ); that is, it works as you expect (the first way). >Linked lists come to mind....without knowing for sure, do I say: >l=l->l_next=new l_list('a',l); // Just an example Yes, if you want the equivalent of l->l_next=new l_list('a',l); l=l->l_next; >or do I say: >l->l_next=l=new l_list('a',l); This is the same as l->l_next = ( l = new l_list( 'a', l ) ); there's no guarantee whether l->l_next will be evaluated (as an lvalue) before the assignment to l. If it's evaluated after, you've got troubles. The *real* question (to my mind) is, what does the constructor l_list::l_list(char,l_list*) do with its second argument? Has it already set the l_next member to point to the given list element? >I know the safe method . . . So why are you mucking around?-) :-) >Chris Fleming, {...,mcnc}!ecsvax!uncw!fleming, fleming@ecsvax!uncw Paul S. R. Chisholm, AT&T Bell Laboratories att!mtunq!psrc, psrc@mtunq.att.com, AT&T Mail !psrchisholm I'm not speaking for the company, I'm just speaking my mind.