Marcus Meissner <meissner@suse.de> writes:
while (*s) { *s++ = toupper(*s); }
loop. What exactly makes the old heretic code so wrong in the eyes of ISO C? A list of example problematic code would be most welcome. (A proper warning from gcc when using optimization would be nice as well.)
The problem here are so called 'sequence points'. ';' is such a sequence point.
Using s and s++ within the same sequence will result in undefined behaviour like you noticed.
while (*s) { ... do stuff ... s++; }
is fine.
Ahah -- that I can see now when spelled out (the programmer only mentioned a change, without any "legaleeze.") But why is there no warning when optimization is turned on? (When the warning is actually needed :-) This is my main point. (I am an old 60's era FORTRAN and assembly language programmer myself, and would use array notation in my own programs by the way :-)