On GCC 9+ this code will print on 3 lines and return 123 if you compile with any optimization options (any of -O options, except, of course -O0). As you can see there is no overflow and c will never be less than a. It should print 20 lines and return 0.Code:#include <stdio.h> int main ( void ) { unsigned int a; unsigned int b; unsigned int c; c = 0; for ( a = 0; a < 10; a++ ) for ( b = 0; b < 2; b++ ) { c++; printf( "a=%u, c=%u\n", a, c ); if ( c < a ) return 123; } return 0; }
Change the comparison to b < N, where N != 2, in the inner loop and will work correctly. Or change the variables to 'int' (signed) and will work correctly.
This bug isn't present on GCC 8 and below.