DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
C language compiler

Preprocessing directives

A preprocessing directive begins with a preprocessing operator, #, on a logical line. Only white spaces are allowed to precede # on the same line. Preprocessing directives can be divided into the following categories:

Preprocessing operators

The preprocessing operators are evaluated left to right, without any defined precedence.


#
A macro parameter preceded by the # preprocessing operator has its corresponding unexpanded argument tokens converted into a string literal. (Any double quotes and backslashes contained in character constants or part of string literals are escaped by a backslash). The # character is sometimes referred to as the ``stringizing'' operator. This rule applies only within function-like macros.

##
If a replacement token sequence contains a ## operator, the ## and any surrounding white space are deleted and adjacent tokens are concatenated, creating a new token. This occurs only when the macro is expanded. See ``Macro definition and expansion''.

Macro definition and expansion

File inclusion

Conditional compilation

Different segments of a program may be compiled conditionally. Conditional compilation statements must observe the following sequence:

  1. One of: #if or #ifdef or #ifndef.

  2. Any number of optional #elif lines.

  3. One optional #else line.

  4. One #endif line.

Line control

Assertions

A line of the form:

   #assert predicate (token-sequence)
associates the token-sequence with the predicate in the assertion name space (separate from the space used for macro definitions). The predicate must be an identifier token.
   #assert predicate
asserts that predicate exists, but does not associate any token sequence with it.

The compiler provides the following predefined predicates by default:

   #assert machine ( i386 )
   #assert system ( unix )
   #assert cpu ( i386 )
Any assertion may be removed by using #unassert, which uses the same syntax as #assert. Using #unassert with no argument deletes all assertions on the predicate; specifying an assertion deletes only that assertion.

An assertion may be tested in a #if statement with the following syntax:

   #if #predicate(non-empty token-list)
For example, the predefined predicate system can be tested with the following line:
   #if #system(unix)
which will evaluate true.

Version control

The #ident directive is used to help administer version control information.

   #ident "version"
puts an arbitrary string in the .comment section of the object file. The .comment section is not loaded into memory when the program is executed.

Pragmas

For more information on pragmas, see ``Pragmas'' in ``ANSI implementation-defined behavior''.

Error generation

A preprocessing line consisting of:

   #error token-sequence
causes the compiler to produce a diagnostic message containing the token-sequence, and stop.

Predefined names

The following identifiers are predefined as object-like macros:

__LINE__ The current line number as a decimal constant.
__FILE__ A string literal representing the name of the file being compiled.
__DATE__ The date of compilation as a string literal in the form "Mmm dd yyyy."
__TIME__ The time of compilation, as a string literal in the form "hh:mm:ss."
__STDC__ The constant 1 under compilation mode -Xc. Under compilation mode -Xk, it is undefined. Under all other compilation modes, it is constant ``0''.
__USLC__ A positive integer constant; its definition signifies a USL C compilation system.
With the exception of __STDC__, these predefined names may not be undefined or redefined. Under compilation mode -Xt, __STDC__ may be undefined (#undef __STDC__) to cause a source file to think it is being compiled by a pre-ANSI C compiler.


Next topic: Declarations and definitions
Previous topic: Preprocessing numbers

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