2.15 Preprocessing

The translation of a C program occurs in several phases. Normally, when the compiler is started, several events occur before the actual compiler starts:

  1. Trigraph sequences (if any) are replaced by single- character internal representations.

  2. Each occurrence of a new-line character immediately preceded by a backslash character is deleted and the following line is spliced to form one logical line.

  3. The source file is decomposed into preprocessing tokens and sequences of white-space characters. Each comment is replaced by one space character.

  4. Preprocessing directives are executed and preprocessor macros are expanded. Files named in #include preprocessing directives are processed through these four steps recursively.

  5. Each source character set member, and each escape sequence in character constants and string literals is converted to a member of the execution character set.

  6. Adjacent character string literal tokens are concatenated and adjacent wide string literal tokens are concatenated.

  7. The resulting stream of tokens is analyzed and translated.

  8. The linking phase. All external object and function references are resolved. Library components are linked to satisfy external references to functions and objects not defined in the current compilation unit. All such linker output is collected into a program image.

The fourth step is called preprocessing, and is handled by a separate unit of the compiler. Each preprocessor directive appears on a line beginning with a pound sign (#); white space may precede the pound sign. These lines are syntactically independent from the rest of the C source file, and can appear anywhere in the source file. Preprocessor directive lines terminate at the end of the logical line.

It is possible to preprocess a source file without actually compiling the program (see your platform-specific DEC C documentation for the available compiler options.) Chapter 8 discusses the preprocessing directives.


Previous Page | Next Page | Table of Contents | Index