Technical article 100792

What does implementation-defined, undefined, and unspecified behavior mean?

OpenServer 5.0.0

Written · Last revised

Problem

What does implementation-defined, undefined, and unspecified
behavior mean?

Solution

Implementation-defined, undefined and unspecified behavior represent areas in which the C standards do not specify what a particular construct, or a program which uses said construct, must do.

The C standard was written with this freedom to give compiler writers the ability to make choices that allow efficient code to be generated, by arranging the constructs as implemented as however the hardware "sees" them, and by also ignoring marginal constructs that are too difficult to precisely define.

These three variations are defined as follows:

IMPLEMENTATION-DEFINED
The implementation must pick some behavior; it may not fail
to compile the program.  The choice must be documented.  The
standard may specify a set of allowable behaviors from which
to choose, or it may impose no specific requirements.
UNSPECIFIED
Like implementation-defined, except that the choice need
not be documented.  Since unspecified behavior may vary from
instance to instance, it is not possible to `check' what the
unspecified behavior is/was, and then assume that the
behavior will stay that way.
UNDEFINED
Anything at all can happen; the standard imposes no
requirements on the behavior of a compiler faced with an
instance of undefined behavior.  The program may fail to
compile, execute incorrectly by crashing, silently
generating incorrect results, or even do exactly what
the programmers wanted.
A programming language standard is a treaty between the
language user (the programmer) and the compiler implementor.
Part of this treaty maintains that the compiler implementor
agrees to provide certain features that the user may assume
will be available.  Other parts of the treaty consist of
rules that the user agrees to follow and that the
implementor may assume will be followed.  As long as both
sides maintain their sides of the treaty, programs have
a strong chance of working correctly.  If _either_ side
reneges on any of its commitments, nothing is guaranteed
to work.

From the Xinuos technical article database, record 100792. Reproduced with permission. The original is at www.sco.com/ta/100792, which is reachable but blocked from search engines. Xinuos marks this article against a retired product line. That refers to the product’s lifecycle, not to whether the advice still works — plenty of it still applies to running systems.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.