Edit: I didn't see the previous 3 posts, nor the ones after, while doing this one.
@JLBorges
Yes, we all agree one should not do that :+) Forgive me for the following, it is pedantic and purely academic;
I only mention it as a means of explaining my earlier comment. I also feel somewhat trite in quoting the standard to you - of all the people :+D And it probably wasn't worth me spending time in making this reply.
But one can compile and execute the code.
I believe you have it as a compiler error because you used
-pedantic-errors Crikey, you taught me to use that, and I do :+) That in itself is a lesson, and
really the argument should end right there. But this time I used cpp.sh with all 3 warnings (
-pedantic not -
pedantic-errors)
This part of the standard, section 1.9.5
5
A conforming implementation executing a well-formed program shall produce the same observable behavior as
one of the possible executions of the corresponding instance of the abstract machine with the same program
and the same input. However, if any such execution contains an undefined operation, this International
Standard places no requirement on the implementation executing that program with that input (not even
with regard to operations preceding the first undefined operation). |
If a program shall not call main, but can be compiled with warnings, and executed, and given the above paragraph does this mean it is UB?
And this bit about the diagnostic:
1.3.25
undefined behavior
behavior for which this International Standard imposes no requirements
[ Note: Undefined behavior may be expected when this International Standard omits any explicit definition of
behavior or when a program uses an erroneous construct or erroneous data. Permissible 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).
Many erroneous program constructs do not engender undefined behavior; they are required to be diagnosed.
— end note ]
|