Complying with standard C

Standard headers

The standard headers are as follows:

assert.h locale.h stddef.h
ctype.h math.h stdio.h
errno.h setjmp.h stdlib.h
float.h signal.h string.h
limits.h stdarg.h time.h
Most implementations will provide more headers, but a strictly conforming ANSI C program can only use these.

Other standards disagree slightly regarding the contents of some of these headers. For example, POSIX (IEEE 1003.1) specifies that fdopen is declared in stdio.h. To allow these two standards to coexist, POSIX requires the macro _POSIX_SOURCE to be #defined prior to the inclusion of any header to guarantee that these additional names exist. (In actuality, the POSIX committee believes that almost the opposite will occur: that _POSIX_SOURCE will be used to limit headers to only those names POSIX describes, and that, by default, headers will contain even more names than POSIX specifies.) X/Open, in its Portability Guide, has also used this macro scheme for its extensions. X/Open's macro is _XOPEN_SOURCE. The following section describes why this scheme is sufficient.

ANSI C requires the standard headers to be both self-sufficient and idempotent. No standard header needs any other header to be #included before or after it, and each standard header can be #included more than once without causing problems. The Standard also requires that its headers be #included only in safe contexts so that the names used in the headers are guaranteed to remain unchanged.

Next topic: Names reserved for implementation use
Previous topic: Balancing process

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003