AFAIK the C standard divides behaviour of different things into four
classes.
1) Defined behaviour. The implementation must do exactly what the
standard says.
2) Implementation-defined behaviour. The implementation must choose some
behaviour, document it, and be consistent about it.
3) Unspecified behaviour. The implementation must pick one of several
possible behaviours, but does not need to be consistent about it.
4) Undefined behaviour. The implementation can do anything it wants to.
Now, let's call the things that cause defined behaviour I, the things
that cause implementation-defined behaviour II, the things that cause
unspecified behaviour III, and the things that cause undefined behaviour
IV.
AFAIK, the compiler is allowed to do any one, or none, of the following:
1) Act as if the C standard defined a strictly set behaviour for I, II,
III and IV.
2) Act as if the C standard defined a strictly set behaviour for I, and
required that the implementation must choose a documented, consistent
behaviour for II, III and IV.
3) Act as if the C standard defined a strictly set behaviour for I,
required that the implementation must choose a documented, consistent
behaviour for II, and required that the implementation must pick one of
several behaviours (but not necessarily consistently) for III and IV.
In other words, this translates to:
1) Act as if everything was defined behaviour.
2) Act as if I was defined behaviour and II, III and IV were
implementation-defined behaviour.
3) Act as if I was defined behaviour, II was implementation-defined
behaviour, and III and IV were unspecified behaviour.
So therefore, if we consider the space of things the standard allows
the implementation to do, defined behaviour is a proper subset of
implementation-defined behaviour, which is a proper subset of
unspecified behaviour, which is a proper subset of undefined behaviour.
For example, painting your house pink is in the set-wise difference
of undefined and unspecified behaviour, and returning 1 from a function
when the program is run once, but returning 2 when it is run again,
without any change in the environment, is in the set-wise difference
of unspecified and implementation-defined behaviour.
Is the above correct? I'd appreciate some sort of in-depth critique.
Thanks.
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"How can we possibly use sex to get what we want? Sex IS what we want."
- Dr. Frasier Crane