The way that term is used in the standard,
is to describe programs outside of any context.
The question is,
"Does the standard place any limitions
on the behavior of this program?"
If the answer is "No", then you have undefined behavior.
I think it is simplest to consider
the behavior of an otherwise correct
program which executes this statement
return (1 / (CHAR_BIT - 7));
as being implementation defined
The way you're contrasting this with "/ (CHAR_BIT - 9)" suggests you
believe CHAR_BIT >= 8. I've heard rumours of systems where it was 7,
but let's ignore that.
I don't believe that your example is implementation defined vis-à-vis
the Standard.
"1.4 Definitions
[intro.defs]
--implementation-defined behavior: Behavior, for a well-formed
program
construct and correct data, that depends on the implementation
and
that each implementation shall document."
If your code divides 1 by some positive value, that has a well-defined
meaning and flow of control that is common to all C++ compilers/
environments, though the exact divisor and result may vary. Nothing
here needs to be documented per implementation.
and the the behavior of an otherwise correct
program which executes this statement
return (1 / (CHAR_BIT - 9));
as being undefined.
Only on a system where CHAR_BIT was equal to 9 would this result in
undefined behaviour. From the Standard:
5.6 Multiplicative operators [expr.mul]
4 ...
If the second operand of / or % is zero the behavior is unde-
fined; otherwise (a/b)*b + a%b is equal to a. If both operands
are
nonnegative then the remainder is nonnegative; if not, the sign of
the
remainder is implementation-defined
This applies at run-time. A program doesn't have some static property
of "undefined behaviour" just because some unsupported inputs could
cause undefined behaviour at run-time. That said, given CHAR_BIT may
be constant for a particular version of a compiler on a particular
system, it may be that compiling and running the program in that
environment will always generate undefined behaviour. Taking the code
in isolation from the compilation environment, it's more likely to
provide a negative divisor, triggering the mixed-signs clause above
and hence implementation-defined behaviour. So, there are three
possible run-time outcomes based on static analysis of the source
code: undefined behaviour, implementation defined behaviour, and well-
defined behaviour.
Cheers,
Tony