------- Comment #18 from tony3 at GarlandConsulting dot us 2010-01-27 20:56 ------- Thanks for the correction - I missed that aspect.
However, a signed version of my simple example still upholds what I'm trying to comment on: it behaves the same way regardless of optimization level (at least as far as the loop exit is in view) -- a forever loop. #include <stdio.h> main() { for (char i = 1 ; i <= 127 ; i++) { printf( "%d ", i); } } This program is always a forever loop, regardless of optimizer setting. The enumeration situation is not--which is my main point: trying to avoid surprising unexpected changes in operation as one changes the optimizer setting. Incidentally, in the above program, the actual print results differ between -O0 and -O2. At -O0 the printed values increment up to 127 and then, as expected change to -128 and count upwards. At -O2 the values increment up to 127 and then continue upward to huge positive integer values (e.g., I terminated the test at 4101552 and counting). It seems at -O2 that the value is no longer considered 8-bit signed. In any case, the forever loop remains a forever loop and doesn't morph into anything radically different. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42810