Download or browse on-line these Using Manual for Red Hat ENTERPRISE LINUX 3 - USING CPP Other.
This manual for Red Hat ENTERPRISE LINUX 3 - USING CPP, given in the PDF format, is available for free online viewing and download without logging on. The guide contains 84 pages, and the size of the file at download is 0.45 Mb. The document type is Using Manual.
[Page 1] Red Hat ENTERPRISE LINUX 3 - USING CPP
Red Hat Enterprise Linux 3 Using cpp, the C Preprocessor ...
[Page 2] Red Hat ENTERPRISE LINUX 3 - USING CPP
Red Hat Enterprise Linux 3: Using cpp, the C Preprocessor Copyright © 1987, 1989, 1991-2003 by Free Software Foundation, Inc. Copyright © 2003 by Red Hat, Inc. This documentation has been prepared by Red Hat, Inc. Red Hat, Inc. 1801 Varsity Drive R...
[Page 3] Red Hat ENTERPRISE LINUX 3 - USING CPP
Table of Contents 1. Overview .......................................................................................................................................... 1 1.1. Initial processing...........................................................
[Page 4] Red Hat ENTERPRISE LINUX 3 - USING CPP
11.2. Implementation limits .................................................................................................... 51 11.3. Obsolete Features..................................................................................................
[Page 5] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 1. Overview The C preprocessor, often known as cpp, is a macro processor that is used automatically by the C compiler to transform your program before compilation. It is called a macro processor because it allows you to define macros, which ...
[Page 6] Red Hat ENTERPRISE LINUX 3 - USING CPP
2 Chapter 1. Overview different one and use it without conversion. (GCC may lose track of the current line number if a file doesn’t consistently use one convention, as sometimes happens when it is edited on computers with different conventions tha...
[Page 7] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 1. Overview 3 But beware of commenting out one end of a block comment with a line comment. // l.c. /* block comment begins oops! this isn’t a comment anymore */ Comments are not recognized within string literals. "/* blah */" is t...
[Page 8] Red Hat ENTERPRISE LINUX 3 - USING CPP
4 Chapter 1. Overview When faced with a sequence of characters that has more than one possible tokenization, the prepro- cessor is greedy. It always makes each token, starting from the left, as big as possible before moving on to the next token. For ...
[Page 9] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 1. Overview 5 is no limit on the length of a character constant, but the value of a character constant that contains more than one character is implementation-defined. Refer to Chapter 11 Implementation Details. Header file names either loo...
[Page 10] Red Hat ENTERPRISE LINUX 3 - USING CPP
6 Chapter 1. Overview • Macro expansion. You can define macros, which are abbreviations for arbitrary fragments of C code. The preprocessor will replace the macros with their definitions throughout the program. Some macros are automatically defi...
[Page 11] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 2. Header Files A header file is a file containing C declarations and macro definitions (Refer to Chapter 3 Macros) to be shared between several source files. You request the use of a header file in your program by including it, with the...
[Page 12] Red Hat ENTERPRISE LINUX 3 - USING CPP
8 Chapter 2. Header Files 2.2. Include Operation The #include directive works by directing the C preprocessor to scan the specified file as input before continuing with the rest of the current file. The output from the preprocessor contains the ou...
[Page 13] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 2. Header Files 9 /usr/include For C++ programs, it will also look in /usr/include/g++-v3, first. In the above, target is the canonical name of the system GCC was configured to compile code for; often but not always the same as the canonica...
[Page 14] Red Hat ENTERPRISE LINUX 3 - USING CPP
10 Chapter 2. Header Files This construct is commonly known as a wrapper #ifndef . When the header is included again, the conditional will be false, because FILE_FOO_SEEN is defined. The preprocessor will skip over the entire contents of the file, ...
[Page 15] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 2. Header Files 11 #include HEADER looks for a file named a\"b. CPP searches for the file according to the rules for double-quoted in- cludes. If the line expands to a token stream beginning with a token and including a token, then the...
[Page 16] Red Hat ENTERPRISE LINUX 3 - USING CPP
12 Chapter 2. Header Files 2.7. System Headers The header files declaring interfaces to the operating system and runtime libraries often cannot be written in strictly conforming C. Therefore, GCC gives code found in system headers special treat- men...
[Page 17] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 3. Macros A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro. There are two kinds of macros. They differ mostly in what they look like when they are used. Object-l...
[Page 18] Red Hat ENTERPRISE LINUX 3 - USING CPP
14 Chapter 3. Macros The most common visible consequence of this is surprising line numbers in error messages. There is no restriction on what can go in a macro body provided it decomposes into valid preprocessing tokens. Parentheses need not balance...
[Page 19] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 3. Macros 15 3.2. Function-like Macros You can also define macros whose use looks like a function call. These are called function-like macros. To define a function-like macro, you use the same #define directive, but you put a pair of parent...
[Page 20] Red Hat ENTERPRISE LINUX 3 - USING CPP
16 Chapter 3. Macros #define min(X, Y) ((X) (Y) ? (X) : (Y)) x = min(a, b); ==> x = ((a) (b) ? (a) : (b)); y = min(1, 2); ==> y = ((1) (2) ? (1) : (2)); z = min(a + 28, *p); ==> z = ((a + 28) (*p) ? (a + 28) : (*p)); (In this small example y...
[Page 21] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 3. Macros 17 Whitespace is not a preprocessing token, so if a macro foo takes one argument, foo () and foo ( ) both supply it an empty argument. Previous GNU preprocessor implementations and documentation were incorrect on this point, insisti...
[Page 22] Red Hat ENTERPRISE LINUX 3 - USING CPP
18 Chapter 3. Macros If you want to stringify the result of expansion of a macro argument, you have to use two levels of macros. #define xstr(s) str(s) #define str(s) #s #define foo 4 str (foo) ==> "foo" xstr (foo) ==> xstr (4) ==>...
[Page 23] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 3. Macros 19 struct command commands[] = { { "quit", quit_command }, { "help", help_command }, ... }; It would be cleaner not to have to give each command name twice, once in the string constant and once in the function na...
[Page 24] Red Hat ENTERPRISE LINUX 3 - USING CPP
20 Chapter 3. Macros using this extension. You cannot use __VA_ARGS__ and this extension in the same macro. You can have named arguments as well as variable arguments in a variadic macro. We could define eprintf like this, instead: #define eprintf(f...
[Page 25] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 3. Macros 21 Previous versions of GNU CPP implemented the comma-deletion extension much more generally. We have restricted it in this release to minimize the differences from C99. To get the same effect with both this and previous versions of...
[Page 26] Red Hat ENTERPRISE LINUX 3 - USING CPP
22 Chapter 3. Macros C99 introduces __func__, and GCC has provided __FUNCTION__ for a long time. Both of these are strings containing the name of the current function (there are slight semantic differences; see the GCC manual). Neither of them is a m...
[Page 27] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 3. Macros 23 3.7.2. Common Predefined Macros The common predefined macros are GNU C extensions. They are available with the same meanings regardless of the machine or operating system on which you are using GNU C. Their names all start with...
[Page 28] Red Hat ENTERPRISE LINUX 3 - USING CPP
24 Chapter 3. Macros __BASE_FILE__ This macro expands to the name of the main input file, in the form of a C string constant. This is the source file that was specified on the command line of the preprocessor or C compiler. __INCLUDE_LEVEL__ This ...
[Page 29] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 3. Macros 25 wchar.h work correctly. You should not use these macros directly; instead, include the appro- priate headers and use the typedefs. __USING_SJLJ_EXCEPTIONS__ This macro is defined, with value 1, if the compiler uses the old mecha...
[Page 30] Red Hat ENTERPRISE LINUX 3 - USING CPP
26 Chapter 3. Macros or || or_eq |= xor ^ xor_eq ^= 3.8. Undefining and Redefining Macros If a macro ceases to be useful, it may be undefined with the #undef directive. #undef takes a single argument, the name of the macro to undefine. You use th...
[Page 31] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 3. Macros 27 3.9. Macro Pitfalls In this section we describe some special rules that apply to macros and macro expansion, and point out certain cases in which the rules have counter-intuitive consequences that you must watch out for. 3.9.1. M...
[Page 32] Red Hat ENTERPRISE LINUX 3 - USING CPP
28 Chapter 3. Macros What we want is this: a = ((b & c) + sizeof (int) - 1)) / sizeof (int); Defining the macro as #define ceil_div(x, y) ((x) + (y) - 1) / (y) provides the desired result. Unintended grouping can result in another way. Consider ...
[Page 33] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 3. Macros 29 if (*p != 0) SKIP_SPACES (p, lim); else ... The presence of two statements--the compound statement and a null statement--in between the if condition and the else makes invalid C code. The definition of the macro SKIP_SPACES can ...
[Page 34] Red Hat ENTERPRISE LINUX 3 - USING CPP
30 Chapter 3. Macros #define min(X, Y) \ ({ typeof (X) x_ = (X); \ typeof (Y) y_ = (Y); \ (x_ y_) ? x_ : y_; }) The ({ ... }) notation produces a compound statement that acts as an expression. Its value is the value of its last statement. This permit...
[Page 35] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 3. Macros 31 then the macro EPERM expands to EPERM. Effectively, it is left alone by the preprocessor whenever it’s used in running text. You can tell that it’s a macro with #ifdef. You might do this if you want to define numeric constan...
[Page 36] Red Hat ENTERPRISE LINUX 3 - USING CPP
32 Chapter 3. Macros If an argument is stringified or concatenated, the prescan does not occur. If you want to expand a macro, then stringify or concatenate its expansion, you can do that by causing one macro to call another macro that does the stri...
[Page 37] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 4. Conditionals A conditional is a directive that instructs the preprocessor to select whether or not to include a chunk of code in the final token stream passed to the compiler. Preprocessor conditionals can test arith- metic expressions, o...
[Page 38] Red Hat ENTERPRISE LINUX 3 - USING CPP
34 Chapter 4. Conditionals #ifdef MACRO controlled text #endif /* MACRO */ This block is called a conditional group. controlled text will be included in the output of the preprocessor if and only if MACRO is defined. We say that the conditional succ...
[Page 39] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 4. Conditionals 35 controlled text #endif /* expression */ expression is a C expression of integer type, subject to stringent restrictions. It may contain • Integer constants. • Character constants, which are interpreted as they would be ...
[Page 40] Red Hat ENTERPRISE LINUX 3 - USING CPP
36 Chapter 4. Conditionals #if defined BUFSIZE && BUFSIZE = 1024 can generally be simplified to just #if BUFSIZE = 1024, since if BUFSIZE is not defined, it will be interpreted as having the value zero. If the defined operator appears as a ...
[Page 41] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 4. Conditionals 37 #elif stands for "else if". Like #else, it goes in the middle of a conditional group and subdivides it; it does not require a matching #endif of its own. Like #if, the #elif directive includes an expression to be ...
[Page 42] Red Hat ENTERPRISE LINUX 3 - USING CPP
38 Chapter 4. Conditionals ...
[Page 43] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 5. Diagnostics The directive #error causes the preprocessor to report a fatal error. The tokens forming the rest of the line following #error are used as the error message. You would use #error inside of a conditional that detects a combinati...
[Page 44] Red Hat ENTERPRISE LINUX 3 - USING CPP
40 Chapter 5. Diagnostics ...
[Page 45] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 6. Line Control The C preprocessor informs the C compiler of the location in your source code where each token came from. Presently, this is just the file name and line number. All the tokens resulting from macro expansion are reported as ha...
[Page 46] Red Hat ENTERPRISE LINUX 3 - USING CPP
42 Chapter 6. Line Control distribution was created. If GCC tries to search for headers in those directories, the build is likely to fail. The new behavior can cause failures too, if the generated file is not in the same directory as its source and ...
[Page 47] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 7. Pragmas The #pragma directive is the method specified by the C standard for providing additional information to the compiler, beyond what is conveyed in the language itself. Three forms of this directive (com- monly known as pragmas) are ...
[Page 48] Red Hat ENTERPRISE LINUX 3 - USING CPP
44 Chapter 7. Pragmas #pragma GCC poison Sometimes, there is an identifier that you want to remove completely from your program, and make sure that it never creeps back in. To enforce this, you can poison the identifier with this pragma. #pragma GC...
[Page 49] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 8. Other Directives The #ident directive takes one argument, a string constant. On some systems, that string constant is copied into a special segment of the object file. On other systems, the directive is ignored. This directive is not part...
[Page 50] Red Hat ENTERPRISE LINUX 3 - USING CPP
46 Chapter 8. Other Directives ...
[Page 51] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 9. Preprocessor Output When the C preprocessor is used with the C, C++, or Objective-C compilers, it is integrated into the compiler and communicates a stream of binary tokens directly to the compiler’s parser. However, it can also be used ...
[Page 52] Red Hat ENTERPRISE LINUX 3 - USING CPP
48 Chapter 9. Preprocessor Output column, and there will be no space between the # and the directive name. If macro expansion happens to generate tokens which might be mistaken for a duplicated directive, a space will be inserted between the # and th...
[Page 53] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 10. Traditional Mode Traditional (pre-standard) C preprocessing is rather different from the preprocessing specified by the standard. When GCC is given the -traditional option, it attempts to emulate a traditional prepro- cessor. We do not g...
[Page 54] Red Hat ENTERPRISE LINUX 3 - USING CPP
50 Chapter 10. Traditional Mode warn about features of ISO C which you must use when you are using a conforming compiler, such as the # and ## operators. Presently -Wtraditional warns about: • Macro parameters that appear within string literals in ...
[Page 55] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 11. Implementation Details Here we document details of how the preprocessor’s implementation affects its user-visible behavior. You should try to avoid undue reliance on behavior described here, as it is possible that it will change subtly ...
[Page 56] Red Hat ENTERPRISE LINUX 3 - USING CPP
52 Chapter 11. Implementation Details Where we say something is limited only by available memory, that means that internal data structures impose no intrinsic limit, and space is allocated with malloc or equivalent. The actual limit will therefore de...
[Page 57] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 11. Implementation Details 53 An assertion looks like this: #predicate (answer) predicate must be a single identifier. answer can be any sequence of tokens; all characters are significant except for leading and trailing whitespace, and diff...
[Page 58] Red Hat ENTERPRISE LINUX 3 - USING CPP
54 Chapter 11. Implementation Details #import is not a well designed feature. It requires the users of a header file to know that it should only be included once. It is much better for the header file’s implementor to write the file so that user...
[Page 59] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 11. Implementation Details 55 GCC 3.0 evaluates # and ## at the same time and strictly left to right. Older versions evaluated all # operators first, then all ## operators, in an unreliable order. • The form of whitespace betwen tokens in ...
[Page 60] Red Hat ENTERPRISE LINUX 3 - USING CPP
56 Chapter 11. Implementation Details ...
[Page 61] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 12. Invocation Most often when you use the C preprocessor you will not have to invoke it explicitly: the C compiler will do so automatically. However, the preprocessor is sometimes useful on its own. All the options listed here are also accep...
[Page 62] Red Hat ENTERPRISE LINUX 3 - USING CPP
58 Chapter 12. Invocation -I dir Add the directory dir to the list of directories to be searched for header files. Refer to Sec- tion 2.3 Search Path. Directories named by -I are searched before the standard system include directories. It is dangero...
[Page 63] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 12. Invocation 59 -pedantic Issue all the mandatory diagnostics listed in the C standard. Some of them are left out by default, since they trigger frequently on harmless code. -pedantic-errors Issue all the mandatory diagnostics, and make all...
[Page 64] Red Hat ENTERPRISE LINUX 3 - USING CPP
60 Chapter 12. Invocation -MT target Change the target of the rule emitted by dependency generation. By default CPP takes the name of the main input file, including any path, deletes any file suffix such as .c, and appends the platform’s usual o...
[Page 65] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 12. Invocation 61 iso9899:1990 c89 The ISO C standard from 1990. c89 is the customary shorthand for this version of the standard. The -ansi option is equivalent to -std=c89. iso9899:199409 The 1990 C standard, as amended in 1994. iso9899:1999...
[Page 66] Red Hat ENTERPRISE LINUX 3 - USING CPP
62 Chapter 12. Invocation -imacros file Exactly like -include, except that any output produced by scanning file is thrown away. Macros it defines remain defined. This allows you to acquire all the macros from a header without also processing its de...
[Page 67] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 12. Invocation 63 -A- Cancel all predefined assertions and all assertions preceding it on the command line. Also, unde- fine all predefined macros and all macros preceding it on the command line. (This is a historical wart and may change i...
[Page 68] Red Hat ENTERPRISE LINUX 3 - USING CPP
64 Chapter 12. Invocation -traditional Try to imitate the behavior of old-fashioned C, as opposed to ISO C. Refer to Chapter 10 Tradi- tional Mode. -trigraphs Process trigraph sequences. Refer to Section 1.1 Initial processing. -remap Enable special ...
[Page 69] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 13. Environment Variables This section describes the environment variables that affect how CPP operates. You can use them to specify directories or prefixes to use when searching for include files, or to control dependency output. Note that...
[Page 70] Red Hat ENTERPRISE LINUX 3 - USING CPP
66 Chapter 13. Environment Variables ...
[Page 71] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 14. GNU Free Documentation License Version 1.1, March 2000 Copyright © 2000 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA Everyone is permitted to copy and distribute verbatim copies of this license do...
[Page 72] Red Hat ENTERPRISE LINUX 3 - USING CPP
68 Chapter 14. GNU Free Documentation License A "Transparent" copy of the Document means a machine-readable copy, represented in a for- mat whose specification is available to the general public, whose contents can be viewed and edited dir...
[Page 73] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 14. GNU Free Documentation License 69 version of the Document. 5. MODIFICATIONS You may copy and distribute a Modified Version of the Document under the conditions of sec- tions 2 and 3 above, provided that you release the Modified Version ...
[Page 74] Red Hat ENTERPRISE LINUX 3 - USING CPP
70 Chapter 14. GNU Free Documentation License You may add a section entitled "Endorsements", provided it contains nothing but endorsements of your Modified Version by various parties--for example, statements of peer review or that the text...
[Page 75] Red Hat ENTERPRISE LINUX 3 - USING CPP
Chapter 14. GNU Free Documentation License 71 permission from their copyright holders, but you may include translations of some or all Invari- ant Sections in addition to the original versions of these Invariant Sections. You may include a translatio...
[Page 76] Red Hat ENTERPRISE LINUX 3 - USING CPP
72 Chapter 14. GNU Free Documentation License ...
[Page 77] Red Hat ENTERPRISE LINUX 3 - USING CPP
Option Index CPP’s command line options are indexed here without any initial - or -. $, Refer to Chapter 12 Invocation A A, Refer to Chapter 12 Invocation A-, Refer to Chapter 12 Invocation ansi, Refer to Chapter 12 Invocation C C, Refer to Chapter...
[Page 78] Red Hat ENTERPRISE LINUX 3 - USING CPP
74 Option Index V v, Refer to Chapter 12 Invocation version, Refer to Chapter 12 Invocation W w, Refer to Chapter 12 Invocation Wall, Refer to Chapter 12 Invocation Wcomment, Refer to Chapter 12 Invocation Wcomments, Refer to Chapter 12 Invocation We...
[Page 79] Red Hat ENTERPRISE LINUX 3 - USING CPP
Index of Directives #assert, Refer to Section 11.3.1 Assertions #define, Refer to Section 3.1 Object-like Macros #elif, Refer to Section 4.2.5 Elif #else, Refer to Section 4.2.4 Else #endif, Refer to Section 4.2.1 Ifdef #error, Refer to Chapter 5 Di...
[Page 80] Red Hat ENTERPRISE LINUX 3 - USING CPP
...
[Page 81] Red Hat ENTERPRISE LINUX 3 - USING CPP
Concept Index # operator, Refer to Section 3.4 Stringification ## operator, Refer to Section 3.5 Concatenation _Pragma, Refer to Chapter 7 Pragmas A alternative tokens, Refer to Section 1.2 Tokenization arguments, Refer to Section 3.3 Macro Argument...
[Page 82] Red Hat ENTERPRISE LINUX 3 - USING CPP
78 Concept Index L line comments, Refer to Section 1.1 Initial processing line control, Refer to Chapter 6 Line Control line endings, Refer to Section 1.1 Initial processing linemarkers, Refer to Chapter 9 Preprocessor Output M macro argument expansi...
[Page 83] Red Hat ENTERPRISE LINUX 3 - USING CPP
Concept Index 79 trigraphs, Refer to Section 1.1 Initial processing U undefining macros, Refer to Section 3.8 Undefining and Redefining Macros unsafe macros, Refer to Section 3.9.4 Duplication of Side Effects V variable number of arguments, Refer ...
[Page 84] Red Hat ENTERPRISE LINUX 3 - USING CPP
Manual (176 pages)
Manual (111 pages)
Reference manual (337 pages)
Release note (26 pages)
User reference manual (76 pages)
Manual (80 pages)