Question 11.33

People seem to make a point of distinguishing between implementation-defined, unspecified, and undefined behavior. What's the difference?


Briefly: implementation-defined means that an implementation must choose some behavior and document it. Unspecified means that an implementation should choose some behavior, but need not document it. Undefined means that absolutely anything might happen. In no case does the Standard impose requirements; in the first two cases it occasionally suggests (and may require a choice from among) a small set of likely behaviors.

Note that since the Standard imposes no requirements on the behavior of a compiler faced with an instance of undefined behavior, the compiler can do absolutely anything. In particular, there is no guarantee that the rest of the program will perform normally. It's perilous to think that you can tolerate undefined behavior in a program; see question 3.2 for a relatively simple example.

If you're interested in writing portable code, you can ignore the distinctions, as you'll want to avoid code that depends on any of the three behaviors.

See also questions 3.9, and 11.34.

References: ANSI Sec. 1.6
ISO Sec. 3.10, Sec. 3.16, Sec. 3.17
Rationale Sec. 1.6


Read sequentially: prev next up top


This page by Steve Summit // Copyright 1995 // mail feedback