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.)
Since when does GCC *assume* the program to be correct?
Posted Apr 18, 2008 19:15 UTC (Fri) by brouhaha (subscriber, #1698)
[Link]
There's a big difference between the (a + foo < a) and (sizeof (a) < 1) cases, which is that the former is something that a programmer is likely to code specifically because he or she knows that the program might (unintentionally) be buggy, in an attempt to catch a bug, while the latter is unlikely to occur at all, and certainly not as something a programmer is likely to deliberately test for.
If it decided that, oh,
that could be true after all, it's choosing an interpretation which the
Standard forbids.
Yet which can actually quite easily happen in real programs. NOWHERE does the standard say that a compiler has to optimize away tests that might always have a fixed value for valid programs, but might easily have differing values for buggy programs.
Perhaps we should spell 'while' differently
when the locale is de_DE?
You've lost me here. I don't see any way that a purely semantic error in a program could result in "while" being misspelled, even if the locale is de_DE.