m |
|||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
− | {{ | + | {{c title|Preprocessor}} |
The '''C preprocessor''' ('''CPP''') is a program that implements the macro language used to transform [[C programming language]] program before they are compiled. Some CPPs can be used as a stand-lone utilities which are called by the [[C]] compiler during the first steps of the translation process. The C preprocessor provides the ability to include additional files, perform basic substitutions, generate errors. The C preprocessor supports conditional statements which allows conditional compilation based on some previously defined configurations. | The '''C preprocessor''' ('''CPP''') is a program that implements the macro language used to transform [[C programming language]] program before they are compiled. Some CPPs can be used as a stand-lone utilities which are called by the [[C]] compiler during the first steps of the translation process. The C preprocessor provides the ability to include additional files, perform basic substitutions, generate errors. The C preprocessor supports conditional statements which allows conditional compilation based on some previously defined configurations. | ||
== Role == | == Role == | ||
− | The C preprocessor is invoked during the first four | + | The C preprocessor is invoked during the first four {{C|phases of translation}}. The preprocessor's job is: |
− | #Perform | + | #Perform {{C|Trigraphs}} replacement |
#Perform escaped new-line characters removal | #Perform escaped new-line characters removal | ||
#Perform tokenization; replace comments with a single space character | #Perform tokenization; replace comments with a single space character | ||
Line 17: | Line 17: | ||
The locations where the files are located, or how the preprocessor identifies standard headers is implementation defined. In the case where the preprocessor does not support the include directive with the double quotes, the preprocessor should treat it as if it was in angled brackets (< and >).<ref>[[C11]] §6.10.2 Source file inclusion p3</ref> Some of the common implementations search system include directories for headers specified with angled brackets while searching the current directory for headers specified with double quotes.<ref>[[C11]] §6.10.2 Source file inclusion p1-2</ref> | The locations where the files are located, or how the preprocessor identifies standard headers is implementation defined. In the case where the preprocessor does not support the include directive with the double quotes, the preprocessor should treat it as if it was in angled brackets (< and >).<ref>[[C11]] §6.10.2 Source file inclusion p3</ref> Some of the common implementations search system include directories for headers specified with angled brackets while searching the current directory for headers specified with double quotes.<ref>[[C11]] §6.10.2 Source file inclusion p1-2</ref> | ||
− | The most common application for the include directive is to include | + | The most common application for the include directive is to include {{C|standard library|standard headers}}. For example, |
<source lang="C"> | <source lang="C"> | ||
Line 24: | Line 24: | ||
== Specs == | == Specs == | ||
− | The exact behavior required for an implementation to become a fully conforming C preprocessor is quite ambiguous. The C Standard description of the preprocessor is based on a preprocessor macro replacement algorithm written by Dave Prosser for the WG14 team in 1984. Some of wording used to produce a clone pseudo-code of the algorithm were intentionally left out of the standard in order to prevent changing the conformance status of existing implementations. This results in various inconsistencies in the C and C++ standards.<ref>[http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#268 WG21, Defect 268, Macro name suppression in rescanned replacement text</ref> | + | The exact behavior required for an implementation to become a fully conforming C preprocessor is quite ambiguous. The C Standard description of the preprocessor is based on a preprocessor macro replacement algorithm written by Dave Prosser for the WG14 team in 1984. Some of wording used to produce a clone pseudo-code of the algorithm were intentionally left out of the standard in order to prevent changing the conformance status of existing implementations. This results in various inconsistencies in the C and C++ standards.<ref>[http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#268 WG21, Defect 268, Macro name suppression in rescanned replacement text]</ref> |
== References == | == References == |
Latest revision as of 06:40, 4 January 2015
The C preprocessor (CPP) is a program that implements the macro language used to transform C programming language program before they are compiled. Some CPPs can be used as a stand-lone utilities which are called by the C compiler during the first steps of the translation process. The C preprocessor provides the ability to include additional files, perform basic substitutions, generate errors. The C preprocessor supports conditional statements which allows conditional compilation based on some previously defined configurations.
Role[edit]
The C preprocessor is invoked during the first four phases of translation. The preprocessor's job is:
- Perform Trigraphs replacement
- Perform escaped new-line characters removal
- Perform tokenization; replace comments with a single space character
- Perform macro expansion
Directives vs text[edit]
The source text is separated into two parts: directives and text lines. Directives must start with a the hash character (#).
Include directive[edit]
The include directive the syntax #include <char-sequence> new-line
or #include "char-sequence"
. The include directive causes the preprocessor to replace that entire line with the entire contents of the file specified.[1]
The locations where the files are located, or how the preprocessor identifies standard headers is implementation defined. In the case where the preprocessor does not support the include directive with the double quotes, the preprocessor should treat it as if it was in angled brackets (< and >).[2] Some of the common implementations search system include directories for headers specified with angled brackets while searching the current directory for headers specified with double quotes.[3]
The most common application for the include directive is to include standard headers. For example,
#include <stdio.h>
Specs[edit]
The exact behavior required for an implementation to become a fully conforming C preprocessor is quite ambiguous. The C Standard description of the preprocessor is based on a preprocessor macro replacement algorithm written by Dave Prosser for the WG14 team in 1984. Some of wording used to produce a clone pseudo-code of the algorithm were intentionally left out of the standard in order to prevent changing the conformance status of existing implementations. This results in various inconsistencies in the C and C++ standards.[4]