Since when does GCC *assume* the program to be correct?
Since when does GCC *assume* the program to be correct?
Posted Apr 18, 2008 11:18 UTC (Fri) by nix (subscriber, #2304)In reply to: Since when does GCC *assume* the program to be correct? by brouhaha
Parent article: GCC and pointer overflows
The problem is that the boundary between 'a C program, but not necessarily a valid one' and 'not a C program' is questionable. if (a + foo < a) is testing something which, in any C program conforming to the Standard without really weird extensions, must be false. This is every bit as true as if (sizeof (a) < 1) would be. If it decided that, oh, that could be true after all, it's choosing an interpretation which the Standard forbids. ... and if the compiler starts accepting that, what other non-C programs should it start accepting? Perhaps we should spell 'while' differently when the locale is de_DE? Perhaps `mary had a little lamb' is now defined as a valid C program? (Sure, compilers can *do* all this, and GCC does have some extensions chosen explicitly because their syntax is invalid Standard C --- the statement-expression extension springs to mind --- but the barrier to new extensions is very high these days, and in any case that doesn't mean that *anything* people do wrong should be defined as a language extension, especially not when it's as weird and devoid of practical utility as this. Portability to other compilers is important.)