Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!munnari.oz.au!mel.dit.csiro.au!yarra!pta!teti!teslab!andrew From: andrew@teslab.lab.OZ (Andrew Phillips) Newsgroups: comp.lang.c++ Subject: Order of evaluation bug in Stroustrup? Message-ID: <1160@teslab.lab.OZ> Date: 28 Nov 90 06:13:27 GMT Reply-To: andrew@teslab.lab.oz.au (Andrew Phillips) Followup-To: comp.lang.c++ Organization: Technology Evaluation Section, L.A.B., Sydney Lines: 45 In "The C++ Programming Language" by Bjarne Stroustrup, on page 204, I found the following which I believe to be a bug according to the rules of C and C++: last = last->next = new ... Since the order of evaluation of subexpressions is undefined it is unclear whether last in last->next refers to the old value of last or the newly assigned value of last. Or am I missing something? BTW I was surprised to find an even more obvious bug on the next page: last = (f==last) ? 0 : f->next; which should have been: if (f == last) last = NULL; else last->next = f->next; although I believe this was fixed in a later printing. Also I was surprised to see that what is the first expression in a for statement in C can be a statement in C++. Presumably this was just added for the convenience of being able to declare a variable in the for loop, so that you can say: for (int i = 0; i < max; ++i) .... But I tried several different kinds of statements in a for loop with the C++ compiler I use and only some work. For example this works: for ( {int i = 0} ; ) ; but this doesn't: for ( for (;;) ; ; ) ; Thanks in advance for any replies to these questions, especially the first one. Andrew. -- Andrew Phillips (andrew@teslab.lab.oz.au) Phone +61 (Aust) 2 (Sydney) 289 8712