Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!munnari.oz.au!mel.dit.csiro.au!yarra!pta!teti!teslab!andrew From: andrew@teslab.lab.OZ (Andrew Phillips) Newsgroups: comp.lang.c++ Subject: Re: Order of evaluation bug in Stroustrup? Message-ID: <1161@teslab.lab.OZ> Date: 4 Dec 90 07:55:02 GMT References: <1160@teslab.lab.OZ> Reply-To: andrew@teslab.lab.oz.au (Andrew Phillips) Organization: Technology Evaluation Section, L.A.B., Sydney Lines: 43 In article <1160@teslab.lab.OZ> andrew@teslab.lab.oz.au (I) wrote: >I found the following which I believe to be a bug according to the >rules of C and C++: > > last = last->next = new ... Thanks to the many people who replied that assignment operators are right associative. However, this does not address the question. Right-associativity means that a=b=c is interpreted as a=(b=c) and not (a=b)=c. But does this mean that the compiler can't interpret it as b=(a=c) [where I'm using brackets to show order of evaluation, even though brackets do not do this in C/C++]? Could someone give a reference to a standard document as to why the above is OK. Well do you think (I do) that this is wrong: last->next = last = ... since the first (right hand side :-) assignment to "last" is a side effect, and so the compiler can use either value of "last" (the old or the new) when evaluating "last->next"? > last = (f==last) ? 0 : f->next; > >which should have been: > > if (f == last) last = NULL; else last->next = f->next; ^^^^^^ (this is important bit) I'm sorry that I mentioned this bug as several people misunderstood what I was saying. You really need to look at several pages of code in (an old version of) the book to see why it is a bug. I now know for a fact that this bug WAS fixed in a later printing. > for ( for (;;) ; ; ) ; This is valid C++ syntax and I've been told does work with at least some compilers. Andrew. -- Andrew Phillips (andrew@teslab.lab.oz.au) Phone +61 (Aust) 2 (Sydney) 289 8712 Brought to you by Super Global Mega Corp .com