[std-interval] Revised document available
Steve Clamage
Stephen.Clamage at Sun.COM
Thu Sep 14 11:37:54 PDT 2006
George Corliss wrote:
>
> Can you help me understand the difference between "undefined" and
> "implementation-dependent" or "implementation-defined"?
The C and C++ standards define these terms.
1. Undefined behavior means the standard places no requirements on the
compile-time or run-time systems. Common responses to code having undefined
behavior are
- refuse to compile
- compile, but fail to link
- link, but crash at run time
- run, but produce an undesired result
- run and produce the result the programmer wanted
Other responses are possible, such as the legendary "reformat the hard drive."
(Suppose a wild jump via an uninitialized pointer goes to the BIOS reformat
command.)
An implementation is allowed to define the behavior of code that is formally
undefined in the standard. Example: Divide-by-zero has undefined behavior, but
an implementation could say that it will always raise a signal, or always abort,
or always return a particular value.
2. Implementation defined means that the standard allows a list or range of
possible behaviors, and the implementation is required to tell you what it does.
Example: Type int must be capable of representing values in the range
[-32767,32767]. The implementation must document what the actual range is, which
almost always wider.
3. Unspecified (a category you didn't list) is similar to
implementation-defined, but the implementation need not tell you what it does.
Example: All the arguments to a function must be fully evaluated before the
function is called, but the evaluation order is unspecified. An implementation
can evaluate them in any order, and does not have to document the order. The
order need not be consistent.
4. Implementation dependent is a generic term that means that the behavior can
vary among systems. The term includes undefined, implementation-defined, and
unspecified behavior.
---
Steve Clamage, stephen.clamage at sun.com
More information about the Std-interval
mailing list