@petit it's GCC's fault for making non-standard extensions available in the first place. This extends to GNU as a whole, it's a really shit habit they have and the entire computer science ecosystem suffers under the heel of their garbage
@petit GNU is perhaps the single largest threat to software quality in our entire ecosystem
long, on undefined behaviours, human sin, computing history and why people should read the C standard before blaming GCC
Are you sure?
Because the #C99 #standard say something different.
On section 3.4.3 the standard defines "undefined behaiour" as "behavior upon use of a nonportable or erroneous program construct or of erroneous data,for which this International Standard imposes no requirements"
The standard also clarify: "Possible undefined behavior ranges from ignoring the situation completely with unpredictable results, to behaving during translation or program execution in a documented manner characteristic of the environment (with or without the issuance of a diagnostic message), to terminating a translation or execution (with the issuance of a diagnostic message)."
In section 4, about Conformance, the #C standard says: "A program that is correct in all other aspects, operating on correct data, containing unspecified behavior shall be a correct program and act in accordance with 5.1.2.3"
And then add "A strictly conforming program shall use only those features of the language and library specified in this International Standard.2)It shall not produce output dependent on any unspecified, undefined, or implementation-defined behavior and shall not exceed any minimum implementation limit."
Note the wording used: in a STRICTLY conforming program the output must not depends on undefined behaviour, but it doesn't exclude undefined behaviours in a CORRECT program!
That's because C was designed as a low level language: undefined behaviour were basically hook for compiler designers.
So ultimately GCC is just handling undefined behaviour BY THE STANDARD.
And this way of handling undefined behaviour is not a C invention.
Algol 68 standard said:
"1.1.4.3. Undefined
a) If something is left “undefined” or is said to be “undefined”, then this means that it is not defined by this Report alone and that, for its definition, information from outside this Report has to be taken into account. {A distinction must be drawn between the yielding of an undefined value (whereupon elaboration continues with possibly unpredictable results) and the complete undefinedness of the further elaboration. The action to be taken in this latter case is at the discretion of the implementer, and may be some form of continuation (but not necessarily the same as any other implementer’s continuation), or some form of interruption (2.1.4.3.h) brought about by some run-time check.}
b) If some condition is “required” to be satisfied during some elaboration then, if it is not so satisfied, the further elaboration is undefined."
Don't blame GNU Compiler Collection!
It's just that we are all tightly coupled!
And we are all brothers, all subject to the original sin. ;-)