In said:
Dan Pop a écrit :
I don't think so. Undefined behaviour stands from the Standard's point
of view, not from the implementation's one. An implementation may define
a behaviour for what the standard leaves undefined.
Do you mean the word "nonportable" in the definition of "undefined
behaviour" is not correct?
It is perfectly correct, it is your interpretation of it that is
incorrect. It is NOT enough for a bit of code to be non-portable to
invoke undefined behaviour, it must satisfy other conditions, clearly
documented in the standard, in the text I have quoted. Why is that so
difficult to understand for you?
Example of non-portable code that does not invoke undefined behaviour:
#include <stdio.h>
int foo(void) { puts("I am foo"); return 1; }
int bar(void) { puts("I am bar"); return 1; }
int main() { return foo() - bar(); }
This is clearly non-portable code, with unpredictable output, as it relies
on unspecified behaviour. Do you claim that it invokes undefined
behaviour? Or that the definition of undefined behaviour is broken?
I know implementations where INT_MAX == 32767 and 12345 * 3 has a well
defined behaviour (the result is -28501);
From the standard's point of view, this is undefined behaviour and, no
matter what the implementation defines/documents, nasal demons are still
allowed by the C standard.
however, this behaviour has to
be found in the implementation documentation, not in the standard, that
do not specify the value of INT_MAX, neither define the behaviour of
12345 * 3 in case of overflow.
And, because it doesn't define it, from its point of view *anything* can
happen after 12345 * 3 is evaluated, the definition provided by the
implementation doesn't change the program status, as far as the C standard
is concerned.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I do not agree with this sentence.
Then, you're a patent idiot. I have quoted you the exact chapter and
verse which specifies WHEN undefined behaviour is invoked. It is sheer
stupidity to invent other situations, based on the definition of undefined
behaviour.
Undefined behaviour is a lack of
definition within the standard, not a property of a program.
Undefined behaviour cannot exist in the absence of a program. Furthermore
in some cases, it is the implementation that decides whether the program
invokes undefined behaviour or not, as in the example with 12345 * 3
(if the implementation defines INT_MAX as 32767, the attempt to evaluate
this expression *unconditionally* invokes undefined behaviour, regardless
of what the documentation says).
Another example:
6 Any pointer type may be converted to an integer type. Except as
previously specified, the result is implementation-defined. If the
result cannot be represented in the integer type, the behavior
is undefined. The result need not be in the range of values of
any integer type.
According to your interpretation, this is undefined behaviour. Then, why
didn't the standard simply say:
6 Converting any pointer type to an integer type invokes undefined
behaviour.
??? What are all the other extra words for?
A program
may be erroneous in a way that seems too complicated for the Standard to
impose a particular behaviour for an implementation.
So what? If it matches any of the conditions listed in the text I have
quoted, it invokes undefined behavior. Otherwise, its behaviour is
unspecified, implementation-defined or well defined.
If you still don't think that undefined behaviour is a portability
issue, guess what is the title of the the annex J, where the undefined
behaviours are recapitulated in J.2.
Your reasoning capabilities are severely damaged: undefined behaviour *is*
a portability issue, but this doesn't mean that *any* portability issue
is undefined behaviour. What about the *other* sections of appendix J?
Aren't they portability issues?
Dan