X-Git-Url: http://git.sourceforge.jp/view?p=pf3gnuchains%2Fgcc-fork.git;a=blobdiff_plain;f=gcc%2Fdoc%2Fcpp.texi;h=631992d517309e9fd80ff3578b4b2e090c44baaa;hp=a9736cdd4543c7bf9180122723da275afb67f664;hb=d80efa726fcb355ff6a45acc49b4142c87fe41b9;hpb=20dd417af30c7acc30f73bad9adf49073e48e6af diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi index a9736cdd454..631992d5173 100644 --- a/gcc/doc/cpp.texi +++ b/gcc/doc/cpp.texi @@ -6,31 +6,25 @@ @c @cropmarks @c @finalout -@macro copyrightnotice +@copying @c man begin COPYRIGHT Copyright @copyright{} 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996, -1997, 1998, 1999, 2000, 2001 +1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation. A copy of -the license is included in the accompanying manual for GCC, in the -section ``GNU Free Documentation License''. +the license is included in the @c man end -@end macro - -@c The manpage doesn't have Front-Cover and Back-Cover Texts, but the -@c complete manual does. -zw - +section entitled ``GNU Free Documentation License''. @ignore @c man begin COPYRIGHT -This manual contains no Invariant Sections, and has no Front-Cover Texts -or Back-Cover Texts. +man page gfdl(7). @c man end @end ignore -@macro covertexts +@c man begin COPYRIGHT This manual contains no Invariant Sections. The Front-Cover Texts are (a) (see below), and the Back-Cover Texts are (b) (see below). @@ -43,12 +37,20 @@ This manual contains no Invariant Sections. The Front-Cover Texts are You have freedom to copy and modify this GNU Manual, like GNU software. Copies published by the Free Software Foundation raise funds for GNU development. -@end macro +@c man end +@end copying @macro gcctabopt{body} @code{\body\} @end macro +@c Create a separate index for command line options. +@defcodeindex op +@syncodeindex vr op + +@c Used in cppopts.texi and cppenv.texi. +@set cppmanual + @ifinfo @dircategory Programming @direntry @@ -66,13 +68,12 @@ This manual contains no Invariant Sections. The Front-Cover Texts are @c There is a fill at the bottom of the page, so we need a filll to @c override it. @vskip 0pt plus 1filll -@copyrightnotice{} -@covertexts{} +@insertcopying @end titlepage @contents @page -@ifinfo +@ifnottex @node Top @top The C preprocessor implements the macro language used to transform C, @@ -92,7 +93,10 @@ useful on its own. * Traditional Mode:: * Implementation Details:: * Invocation:: +* Environment Variables:: +* GNU Free Documentation License:: * Index of Directives:: +* Option Index:: * Concept Index:: @detailmenu @@ -100,6 +104,7 @@ useful on its own. Overview +* Character sets:: * Initial processing:: * Tokenization:: * The preprocessing language:: @@ -124,6 +129,7 @@ Macros * Variadic Macros:: * Predefined Macros:: * Undefining and Redefining Macros:: +* Directives Within Macro Arguments:: * Macro Pitfalls:: Predefined Macros @@ -168,14 +174,12 @@ Obsolete Features * Assertions:: * Obsolete once-only headers:: -* Miscellaneous obsolete features:: @end detailmenu @end menu -@copyrightnotice{} -@covertexts{} -@end ifinfo +@insertcopying +@end ifnottex @node Overview @chapter Overview @@ -197,7 +201,7 @@ will be removed, and the Makefile will not work. Having said that, you can often get away with using cpp on things which are not C@. Other Algol-ish programming languages are often safe -(Pascal, Ada, etc.) So is assembly, with caution. @option{-traditional} +(Pascal, Ada, etc.) So is assembly, with caution. @option{-traditional-cpp} mode preserves more white space, and is otherwise more permissive. Many of the problems can be avoided by writing C or C++ style comments instead of native language comments, and keeping macros simple. @@ -217,49 +221,101 @@ of a program which does not expect them. To get strict ISO Standard C, you should use the @option{-std=c89} or @option{-std=c99} options, depending on which version of the standard you want. To get all the mandatory diagnostics, you must also use @option{-pedantic}. @xref{Invocation}. + +This manual describes the behavior of the ISO preprocessor. To +minimize gratuitous differences, where the ISO preprocessor's +behavior does not conflict with traditional semantics, the +traditional preprocessor should behave the same way. The various +differences that do exist are detailed in the section @ref{Traditional +Mode}. + +For clarity, unless noted otherwise, references to @samp{CPP} in this +manual refer to GNU CPP. @c man end @menu +* Character sets:: * Initial processing:: * Tokenization:: * The preprocessing language:: @end menu +@node Character sets +@section Character sets + +Source code character set processing in C and related languages is +rather complicated. The C standard discusses two character sets, but +there are really at least four. + +The files input to CPP might be in any character set at all. CPP's +very first action, before it even looks for line boundaries, is to +convert the file into the character set it uses for internal +processing. That set is what the C standard calls the @dfn{source} +character set. It must be isomorphic with ISO 10646, also known as +Unicode. CPP uses the UTF-8 encoding of Unicode. + +At present, GNU CPP does not implement conversion from arbitrary file +encodings to the source character set. Use of any encoding other than +plain ASCII or UTF-8, except in comments, will cause errors. Use of +encodings that are not strict supersets of ASCII, such as Shift JIS, +may cause errors even if non-ASCII characters appear only in comments. +We plan to fix this in the near future. + +All preprocessing work (the subject of the rest of this manual) is +carried out in the source character set. If you request textual +output from the preprocessor with the @option{-E} option, it will be +in UTF-8. + +After preprocessing is complete, string and character constants are +converted again, into the @dfn{execution} character set. This +character set is under control of the user; the default is UTF-8, +matching the source character set. Wide string and character +constants have their own character set, which is not called out +specifically in the standard. Again, it is under control of the user. +The default is UTF-16 or UTF-32, whichever fits in the target's +@code{wchar_t} type, in the target machine's byte +order.@footnote{UTF-16 does not meet the requirements of the C +standard for a wide character set, but the choice of 16-bit +@code{wchar_t} is enshrined in some system ABIs so we cannot fix +this.} Octal and hexadecimal escape sequences do not undergo +conversion; @t{'\x12'} has the value 0x12 regardless of the currently +selected execution character set. All other escapes are replaced by +the character in the source character set that they represent, then +converted to the execution character set, just like unescaped +characters. + +GCC does not permit the use of characters outside the ASCII range, nor +@samp{\u} and @samp{\U} escapes, in identifiers. We hope this will +change eventually, but there are problems with the standard semantics +of such ``extended identifiers'' which must be resolved through the +ISO C and C++ committees first. + @node Initial processing @section Initial processing The preprocessor performs a series of textual transformations on its input. These happen before all other processing. Conceptually, they happen in a rigid order, and the entire file is run through each -transformation before the next one begins. GNU CPP actually does them +transformation before the next one begins. CPP actually does them all at once, for performance reasons. These transformations correspond roughly to the first three ``phases of translation'' described in the C standard. @enumerate @item -@cindex character sets @cindex line endings The input file is read into memory and broken into lines. -GNU CPP expects its input to be a text file, that is, an unstructured -stream of ASCII characters, with some characters indicating the end of a -line of text. Extended ASCII character sets, such as ISO Latin-1 or -Unicode encoded in UTF-8, are also acceptable. Character sets that are -not strict supersets of seven-bit ASCII will not work. We plan to add -complete support for international character sets in a future release. - Different systems use different conventions to indicate the end of a line. GCC accepts the ASCII control sequences @kbd{LF}, @kbd{@w{CR -LF}}, @kbd{CR}, and @kbd{@w{LF CR}} as end-of-line markers. The first -three are the canonical sequences used by Unix, DOS and VMS, and the -classic Mac OS (before OSX) respectively. You may therefore safely copy -source code written on any of those systems to a 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 that share a -network file system.) @kbd{@w{LF CR}} is included because it has been -reported as an end-of-line marker under exotic conditions. +LF}} and @kbd{CR} as end-of-line markers. These are the canonical +sequences used by Unix, DOS and VMS, and the classic Mac OS (before +OSX) respectively. You may therefore safely copy source code written +on any of those systems to a 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 that share a network +file system.) If the last line of any input file lacks an end-of-line marker, the end of the file is considered to implicitly supply one. The C standard says @@ -268,34 +324,37 @@ warning message. @item @cindex trigraphs -If trigraphs are enabled, they are replaced by their corresponding -single characters. +@anchor{trigraphs}If trigraphs are enabled, they are replaced by their +corresponding single characters. By default GCC ignores trigraphs, +but if you request a strictly conforming mode with the @option{-std} +option, or you specify the @option{-trigraphs} option, then it +converts them. These are nine three-character sequences, all starting with @samp{??}, that are defined by ISO C to stand for single characters. They permit obsolete systems that lack some of C's punctuation to use C@. For example, @samp{??/} stands for @samp{\}, so @t{'??/n'} is a character -constant for a newline. By default, GCC ignores trigraphs, but if you -request a strictly conforming mode with the @option{-std} option, then -it converts them. +constant for a newline. -Trigraphs are not popular and many compilers implement them incorrectly. -Portable code should not rely on trigraphs being either converted or -ignored. If you use the @option{-Wall} or @option{-Wtrigraphs} options, -GCC will warn you when a trigraph would change the meaning of your -program if it were converted. +Trigraphs are not popular and many compilers implement them +incorrectly. Portable code should not rely on trigraphs being either +converted or ignored. With @option{-Wtrigraphs} GCC will warn you +when a trigraph may change the meaning of your program if it were +converted. @xref{Wtrigraphs}. -In a string constant, you can prevent a sequence of question marks from -being confused with a trigraph by inserting a backslash between the -question marks. @t{"(??\?)"} is the string @samp{(???)}, not -@samp{(?]}. Traditional C compilers do not recognize this idiom. +In a string constant, you can prevent a sequence of question marks +from being confused with a trigraph by inserting a backslash between +the question marks, or by separating the string literal at the +trigraph and making use of string literal concatenation. @t{"(??\?)"} +is the string @samp{(???)}, not @samp{(?]}. Traditional C compilers +do not recognize these idioms. The nine trigraphs and their replacements are -@example +@smallexample Trigraph: ??( ??) ??< ??> ??= ??/ ??' ??! ??- Replacement: [ ] @{ @} # \ ^ | ~ -@end example +@end smallexample @item @cindex continued lines @@ -326,23 +385,23 @@ There are two kinds of comments. @dfn{Block comments} begin with @samp{/*} and continue until the next @samp{*/}. Block comments do not nest: -@example +@smallexample /* @r{this is} /* @r{one comment} */ @r{text outside comment} -@end example +@end smallexample @dfn{Line comments} begin with @samp{//} and continue to the end of the current line. Line comments do not nest either, but it does not matter, because they would end in the same place anyway. -@example +@smallexample // @r{this is} // @r{one comment} @r{text outside comment} -@end example +@end smallexample @end enumerate It is safe to put line comments inside block comments, or vice versa. -@example +@smallexample @group /* @r{block comment} // @r{contains line comment} @@ -351,20 +410,21 @@ It is safe to put line comments inside block comments, or vice versa. // @r{line comment} /* @r{contains block comment} */ @end group -@end example +@end smallexample But beware of commenting out one end of a block comment with a line comment. -@example +@smallexample @group // @r{l.c.} /* @r{block comment begins} @r{oops! this isn't a comment anymore} */ @end group -@end example +@end smallexample -Comments are not recognized within string literals. @t{@w{"/* blah -*/"}} is the string constant @samp{@w{/* blah */}}, not an empty string. +Comments are not recognized within string literals. +@t{@w{"/* blah */"}} is the string constant @samp{@w{/* blah */}}, not +an empty string. Line comments are not in the 1989 edition of the C standard, but they are recognized by GCC as an extension. In C++ and in the 1999 edition @@ -377,7 +437,7 @@ next line with backslash-newline. You can even split @samp{/*}, @samp{*/}, and @samp{//} onto multiple lines with backslash-newline. For example: -@example +@smallexample @group /\ * @@ -387,7 +447,7 @@ ne FO\ O 10\ 20 @end group -@end example +@end smallexample @noindent is equivalent to @code{@w{#define FOO 1020}}. All these tricks are @@ -395,26 +455,8 @@ extremely confusing and should not be used in code intended to be readable. There is no way to prevent a backslash at the end of a line from being -interpreted as a backslash-newline. - -@example -"foo\\ -bar" -@end example - -@noindent -is equivalent to @code{"foo\bar"}, not to @code{"foo\\bar"}. To avoid -having to worry about this, do not use the deprecated GNU extension -which permits multi-line strings. Instead, use string literal -concatenation: - -@example - "foo\\" - "bar" -@end example - -@noindent -Your program will be more portable this way, too. +interpreted as a backslash-newline. This cannot affect any correct +program, however. @node Tokenization @section Tokenization @@ -440,7 +482,7 @@ Once the input file is broken into tokens, the token boundaries never change, except when the @samp{##} preprocessing operator is used to paste tokens together. @xref{Concatenation}. For example, -@example +@smallexample @group #define foo() bar foo()baz @@ -448,7 +490,7 @@ foo()baz @emph{not} @expansion{} barbaz @end group -@end example +@end smallexample The compiler does not re-tokenize the preprocessor's output. Each preprocessing token becomes one compiler token. @@ -529,11 +571,10 @@ closing quote or angle bracket. The preprocessor looks for the header file in different places depending on which form you use. @xref{Include Operation}. -In standard C, no string literal may extend past the end of a line. GNU -CPP accepts multi-line string constants, but not multi-line character -constants or header file names. This extension is deprecated and will -be removed in GCC 3.1. You may use continued lines instead, or string -constant concatenation. @xref{Differences from previous versions}. +No string literal may extend past the end of a line. Older versions +of GCC accepted multi-line string constants. You may use continued +lines instead, or string constant concatenation. @xref{Differences +from previous versions}. @cindex punctuators @cindex digraphs @@ -549,10 +590,10 @@ punctuation in obsolete systems. It has no negative side effects, unlike trigraphs, but does not cover as much ground. The digraphs and their corresponding normal punctuators are: -@example +@smallexample Digraph: <% %> <: :> %: %:%: Punctuator: @{ @} [ ] # ## -@end example +@end smallexample @cindex other tokens Any other single character is considered ``other.'' It is passed on to @@ -572,10 +613,10 @@ silently ignored, just as any other character would be. In running text, NUL is considered white space. For example, these two directives have the same meaning. -@example +@smallexample #define X^@@1 #define X 1 -@end example +@end smallexample @noindent (where @samp{^@@} is ASCII NUL)@. Within string or character constants, @@ -718,9 +759,11 @@ named @var{file} in a standard list of system directories. You can prepend directories to this list with the @option{-I} option (@pxref{Invocation}). @item #include "@var{file}" -This variant is used for header files of your own program. It searches -for a file named @var{file} first in the directory containing the -current file, then in the same directories used for @code{<@var{file}>}. +This variant is used for header files of your own program. It +searches for a file named @var{file} first in the directory containing +the current file, then in the quote directories and then the same +directories used for @code{<@var{file}>}. You can prepend directories +to the list of quote directories with the @option{-iquote} option. @end table The argument of @samp{#include}, whether delimited with quote marks or @@ -750,15 +793,15 @@ file, followed by the output that comes from the text after the @samp{#include} directive. For example, if you have a header file @file{header.h} as follows, -@example +@smallexample char *test (void); -@end example +@end smallexample @noindent and a main program called @file{program.c} that uses the header file, like this, -@example +@smallexample int x; #include "header.h" @@ -767,13 +810,13 @@ main (void) @{ puts (test ()); @} -@end example +@end smallexample @noindent the compiler will see the same token stream as it would if @file{program.c} read -@example +@smallexample int x; char *test (void); @@ -782,17 +825,17 @@ main (void) @{ puts (test ()); @} -@end example +@end smallexample Included files are not limited to declarations and macro definitions; those are merely the typical uses. Any fragment of a C program can be included from another file. The include file could even contain the beginning of a statement that is concluded in the containing file, or the end of a statement that was started in the including file. However, -a comment or a string or character constant may not start in the -included file and finish in the including file. An unterminated -comment, string constant or character constant in an included file is -considered to end (with an error message) at the end of the file. +an included file must consist of complete tokens. Comments and string +literals which have not been closed by the end of an included file are +invalid. For error recovery, they are considered to end at the end of +the file. To avoid confusion, it is best if header files contain only complete syntactic units---function declarations or definitions, type @@ -809,12 +852,12 @@ GCC looks in several different places for headers. On a normal Unix system, if you do not instruct it otherwise, it will look for headers requested with @code{@w{#include <@var{file}>}} in: -@example +@smallexample /usr/local/include -/usr/lib/gcc-lib/@var{target}/@var{version}/include +@var{libdir}/gcc/@var{target}/@var{version}/include /usr/@var{target}/include /usr/include -@end example +@end smallexample For C++ programs, it will also look in @file{/usr/include/g++-v3}, first. In the above, @var{target} is the canonical name of the system @@ -824,25 +867,31 @@ version of GCC in use. You can add to this list with the @option{-I@var{dir}} command line option. All the directories named by @option{-I} are searched, in -left-to-right order, @emph{before} the default directories. You can -also prevent GCC from searching any of the default directories with the -@option{-nostdinc} option. This is useful when you are compiling an +left-to-right order, @emph{before} the default directories. The only +exception is when @file{dir} is already searched by default. In +this case, the option is ignored and the search order for system +directories remains unchanged. + +Duplicate directories are removed from the quote and bracket search +chains before the two chains are merged to make the final search chain. +Thus, it is possible for a directory to occur twice in the final search +chain if it was specified in both the quote and bracket chains. + +You can prevent GCC from searching any of the default directories with +the @option{-nostdinc} option. This is useful when you are compiling an operating system kernel or some other program that does not use the standard C library facilities, or the standard C library itself. +@option{-I} options are not ignored as described above when +@option{-nostdinc} is in effect. GCC looks for headers requested with @code{@w{#include "@var{file}"}} -first in the directory containing the current file, then in the same -places it would have looked for a header requested with angle brackets. -For example, if @file{/usr/include/sys/stat.h} contains +first in the directory containing the current file, then in the +directories as specified by @option{-iquote} options, then in the same +places it would have looked for a header requested with angle +brackets. For example, if @file{/usr/include/sys/stat.h} contains @code{@w{#include "types.h"}}, GCC looks for @file{types.h} first in @file{/usr/include/sys}, then in its usual search path. -If you name a search directory with @option{-I@var{dir}} that is also a -system include directory, the @option{-I} wins; the directory will be -searched according to the @option{-I} ordering, and it will not be -treated as a system include directory. GCC will warn you when a system -include directory is hidden in this way. - @samp{#line} (@pxref{Line Control}) does not change GCC's idea of the directory containing the current file. @@ -852,7 +901,8 @@ This has two effects. First, directories appearing before the quote marks. Directories after @option{-I-} are searched for all headers. Second, the directory containing the current file is not searched for anything, unless it happens to be one of the directories -named by an @option{-I} switch. +named by an @option{-I} switch. @option{-I-} is deprecated, -iquote +should be used instead. @option{-I. -I-} is not the same as no @option{-I} options at all, and does not cause the same behavior for @samp{<>} includes that @samp{""} @@ -880,7 +930,7 @@ it will certainly waste time. The standard way to prevent this is to enclose the entire real contents of the file in a conditional, like this: -@example +@smallexample @group /* File foo. */ #ifndef FILE_FOO_SEEN @@ -890,7 +940,7 @@ of the file in a conditional, like this: #endif /* !FILE_FOO_SEEN */ @end group -@end example +@end smallexample This construct is commonly known as a @dfn{wrapper #ifndef}. When the header is included again, the conditional will be false, @@ -898,7 +948,7 @@ because @code{FILE_FOO_SEEN} is defined. The preprocessor will skip over the entire contents of the file, and the compiler will not see it twice. -GNU CPP optimizes even further. It remembers when a header file has a +CPP optimizes even further. It remembers when a header file has a wrapper @samp{#ifndef}. If a subsequent @samp{#include} specifies that header, and the macro in the @samp{#ifndef} is still defined, it does not bother to rescan the file at all. @@ -925,7 +975,7 @@ files to be included into your program. They might specify configuration parameters to be used on different sorts of operating systems, for instance. You could do this with a series of conditionals, -@example +@smallexample #if SYSTEM_1 # include "system_1.h" #elif SYSTEM_2 @@ -933,18 +983,18 @@ systems, for instance. You could do this with a series of conditionals, #elif SYSTEM_3 @dots{} #endif -@end example +@end smallexample That rapidly becomes tedious. Instead, the preprocessor offers the ability to use a macro for the header name. This is called a @dfn{computed include}. Instead of writing a header name as the direct argument of @samp{#include}, you simply put a macro name there instead: -@example +@smallexample #define SYSTEM_H "system_1.h" @dots{} #include SYSTEM_H -@end example +@end smallexample @noindent @code{SYSTEM_H} will be expanded, and the preprocessor will look for @@ -969,10 +1019,10 @@ string constant are the file to be included. CPP does not re-examine the string for embedded quotes, but neither does it process backslash escapes in the string. Therefore -@example +@smallexample #define HEADER "a\"b" #include HEADER -@end example +@end smallexample @noindent looks for a file named @file{a\"b}. CPP searches for the file according @@ -1017,9 +1067,9 @@ header is not protected from multiple inclusion (@pxref{Once-Only Headers}), it will recurse infinitely and cause a fatal error. You could include the old header with an absolute pathname: -@example +@smallexample #include "/usr/include/old-header.h" -@end example +@end smallexample @noindent This works, but is not clean; should the system headers ever move, you would have to edit the new headers to match. @@ -1075,8 +1125,8 @@ found in that directory will be considered system headers. All directories named by @option{-isystem} are searched @emph{after} all directories named by @option{-I}, no matter what their order was on the command line. If the same directory is named by both @option{-I} and -@option{-isystem}, @option{-I} wins; it is as if the @option{-isystem} option -had never been specified at all. GCC warns you when this happens. +@option{-isystem}, the @option{-I} option is ignored. GCC provides an +informative message when this occurs if @option{-v} is used. @findex #pragma GCC system_header There is also a directive, @code{@w{#pragma GCC system_header}}, which @@ -1117,6 +1167,7 @@ macros when you are compiling C++. * Variadic Macros:: * Predefined Macros:: * Undefining and Redefining Macros:: +* Directives Within Macro Arguments:: * Macro Pitfalls:: @end menu @@ -1137,29 +1188,29 @@ followed by the name of the macro and then the token sequence it should be an abbreviation for, which is variously referred to as the macro's @dfn{body}, @dfn{expansion} or @dfn{replacement list}. For example, -@example +@smallexample #define BUFFER_SIZE 1024 -@end example +@end smallexample @noindent defines a macro named @code{BUFFER_SIZE} as an abbreviation for the token @code{1024}. If somewhere after this @samp{#define} directive there comes a C statement of the form -@example +@smallexample foo = (char *) malloc (BUFFER_SIZE); -@end example +@end smallexample @noindent then the C preprocessor will recognize and @dfn{expand} the macro @code{BUFFER_SIZE}. The C compiler will see the same tokens as it would if you had written -@example +@smallexample foo = (char *) malloc (1024); -@end example +@end smallexample -By convention, macro names are written in upper case. Programs are +By convention, macro names are written in uppercase. Programs are easier to read when it is possible to tell at a glance which names are macros. @@ -1168,13 +1219,13 @@ continue the definition onto multiple lines, if necessary, using backslash-newline. When the macro is expanded, however, it will all come out on one line. For example, -@example +@smallexample #define NUMBERS 1, \ 2, \ 3 int x[] = @{ NUMBERS @}; @expansion{} int x[] = @{ 1, 2, 3 @}; -@end example +@end smallexample @noindent The most common visible consequence of this is surprising line numbers @@ -1189,25 +1240,25 @@ The C preprocessor scans your program sequentially. Macro definitions take effect at the place you write them. Therefore, the following input to the C preprocessor -@example +@smallexample foo = X; #define X 4 bar = X; -@end example +@end smallexample @noindent produces -@example +@smallexample foo = X; bar = 4; -@end example +@end smallexample When the preprocessor expands a macro name, the macro's expansion replaces the macro invocation, then the expansion is examined for more macros to expand. For example, -@example +@smallexample @group #define TABLESIZE BUFSIZE #define BUFSIZE 1024 @@ -1215,7 +1266,7 @@ TABLESIZE @expansion{} BUFSIZE @expansion{} 1024 @end group -@end example +@end smallexample @noindent @code{TABLESIZE} is expanded first to produce @code{BUFSIZE}, then that @@ -1233,12 +1284,12 @@ at some point in the source file. @code{TABLESIZE}, defined as shown, will always expand using the definition of @code{BUFSIZE} that is currently in effect: -@example +@smallexample #define BUFSIZE 1020 #define TABLESIZE BUFSIZE #undef BUFSIZE #define BUFSIZE 37 -@end example +@end smallexample @noindent Now @code{TABLESIZE} expands (in two stages) to @code{37}. @@ -1257,24 +1308,24 @@ are called @dfn{function-like macros}. To define a function-like macro, you use the same @samp{#define} directive, but you put a pair of parentheses immediately after the macro name. For example, -@example +@smallexample #define lang_init() c_init() lang_init() @expansion{} c_init() -@end example +@end smallexample A function-like macro is only expanded if its name appears with a pair of parentheses after it. If you write just the name, it is left alone. This can be useful when you have a function and a macro of the same name, and you wish to use the function sometimes. -@example +@smallexample extern void foo(void); #define foo() /* optimized inline version */ @dots{} foo(); funcptr = foo; -@end example +@end smallexample Here the call to @code{foo()} will use the macro, but the function pointer will get the address of the real function. If the macro were to @@ -1285,11 +1336,11 @@ macro definition, that does not define a function-like macro, it defines an object-like macro whose expansion happens to begin with a pair of parentheses. -@example +@smallexample #define lang_init () c_init() lang_init() @expansion{} () c_init()() -@end example +@end smallexample The first two pairs of parentheses in this expansion come from the macro. The third is the pair that was originally after the macro @@ -1321,12 +1372,12 @@ macro body.) As an example, here is a macro that computes the minimum of two numeric values, as it is defined in many C programs, and some uses. -@example +@smallexample #define min(X, Y) ((X) < (Y) ? (X) : (Y)) x = min(a, b); @expansion{} x = ((a) < (b) ? (a) : (b)); y = min(1, 2); @expansion{} y = ((1) < (2) ? (1) : (2)); z = min(a + 28, *p); @expansion{} z = ((a + 28) < (*p) ? (a + 28) : (*p)); -@end example +@end smallexample @noindent (In this small example you can already see several of the dangers of @@ -1339,9 +1390,9 @@ such parentheses does not end the argument. However, there is no requirement for square brackets or braces to balance, and they do not prevent a comma from separating arguments. Thus, -@example +@smallexample macro (array[x = y, x + 1]) -@end example +@end smallexample @noindent passes two arguments to @code{macro}: @code{array[x = y} and @code{x + @@ -1359,20 +1410,20 @@ Prescan}, for detailed discussion. For example, @code{min (min (a, b), c)} is first expanded to -@example +@smallexample min (((a) < (b) ? (a) : (b)), (c)) -@end example +@end smallexample @noindent and then to -@example +@smallexample @group ((((a) < (b) ? (a) : (b))) < (c) ? (((a) < (b) ? (a) : (b))) : (c)) @end group -@end example +@end smallexample @noindent (Line breaks shown here for clarity would not actually be generated.) @@ -1384,7 +1435,7 @@ You cannot leave out arguments entirely; if a macro takes two arguments, there must be exactly one comma at the top level of its argument list. Here are some silly examples using @code{min}: -@example +@smallexample min(, b) @expansion{} (( ) < (b) ? ( ) : (b)) min(a, ) @expansion{} ((a ) < ( ) ? (a ) : ( )) min(,) @expansion{} (( ) < ( ) ? ( ) : ( )) @@ -1392,7 +1443,7 @@ min((,),) @expansion{} (((,)) < ( ) ? ((,)) : ( )) min() @error{} macro "min" requires 2 arguments, but only 1 given min(,,) @error{} macro "min" passed 3 arguments, but takes just 2 -@end example +@end smallexample Whitespace is not a preprocessing token, so if a macro @code{foo} takes one argument, @code{@w{foo ()}} and @code{@w{foo ( )}} both supply it an @@ -1404,10 +1455,10 @@ empty argument was required. Macro parameters appearing inside string literals are not replaced by their corresponding actual arguments. -@example +@smallexample #define foo(x) x, "x" foo(bar) @expansion{} bar, "x" -@end example +@end smallexample @node Stringification @section Stringification @@ -1431,7 +1482,7 @@ long string. Here is an example of a macro definition that uses stringification: -@example +@smallexample @group #define WARN_IF(EXP) \ do @{ if (EXP) \ @@ -1441,7 +1492,7 @@ WARN_IF (x == 0); @expansion{} do @{ if (x == 0) fprintf (stderr, "Warning: " "x == 0" "\n"); @} while (0); @end group -@end example +@end smallexample @noindent The argument for @code{EXP} is substituted once, as-is, into the @@ -1474,7 +1525,7 @@ There is no way to convert a macro argument into a character constant. If you want to stringify the result of expansion of a macro argument, you have to use two levels of macros. -@example +@smallexample #define xstr(s) str(s) #define str(s) #s #define foo 4 @@ -1484,7 +1535,7 @@ xstr (foo) @expansion{} xstr (4) @expansion{} str (4) @expansion{} "4" -@end example +@end smallexample @code{s} is stringified when it is used in @code{str}, so it is not macro-expanded first. But @code{s} is an ordinary argument to @@ -1541,7 +1592,7 @@ Consider a C program that interprets named commands. There probably needs to be a table of commands, perhaps an array of structures declared as follows: -@example +@smallexample @group struct command @{ @@ -1558,7 +1609,7 @@ struct command commands[] = @dots{} @}; @end group -@end example +@end smallexample It would be cleaner not to have to give each command name twice, once in the string constant and once in the function name. A macro which takes the @@ -1566,7 +1617,7 @@ name of a command as an argument can make this unnecessary. The string constant can be created with stringification, and the function name by concatenating the argument with @samp{_command}. Here is how it is done: -@example +@smallexample #define COMMAND(NAME) @{ #NAME, NAME ## _command @} struct command commands[] = @@ -1575,7 +1626,7 @@ struct command commands[] = COMMAND (help), @dots{} @}; -@end example +@end smallexample @node Variadic Macros @section Variadic Macros @@ -1587,9 +1638,9 @@ A macro can be declared to accept a variable number of arguments much as a function can. The syntax for defining the macro is similar to that of a function. Here is an example: -@example +@smallexample #define eprintf(@dots{}) fprintf (stderr, __VA_ARGS__) -@end example +@end smallexample This kind of macro is called @dfn{variadic}. When the macro is invoked, all the tokens in its argument list after the last named argument (this @@ -1598,10 +1649,10 @@ argument}. This sequence of tokens replaces the identifier @code{@w{__VA_ARGS__}} in the macro body wherever it appears. Thus, we have this expansion: -@example +@smallexample eprintf ("%s:%d: ", input_file, lineno) @expansion{} fprintf (stderr, "%s:%d: ", input_file, lineno) -@end example +@end smallexample The variable argument is completely macro-expanded before it is inserted into the macro expansion, just like an ordinary argument. You may use @@ -1610,25 +1661,25 @@ or to paste its leading or trailing token with another token. (But see below for an important special case for @samp{##}.) If your macro is complicated, you may want a more descriptive name for -the variable argument than @code{@w{__VA_ARGS__}}. GNU CPP permits +the variable argument than @code{@w{__VA_ARGS__}}. CPP permits this, as an extension. You may write an argument name immediately before the @samp{@dots{}}; that name is used for the variable argument. The @code{eprintf} macro above could be written -@example +@smallexample #define eprintf(args@dots{}) fprintf (stderr, args) -@end example +@end smallexample @noindent -using this extension. You cannot use @code{__VA_ARGS__} and this +using this extension. You cannot use @code{@w{__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 @code{eprintf} like this, instead: -@example +@smallexample #define eprintf(format, @dots{}) fprintf (stderr, format, __VA_ARGS__) -@end example +@end smallexample @noindent This formulation looks more descriptive, but unfortunately it is less @@ -1638,26 +1689,26 @@ argument from the variable arguments. Furthermore, if you leave the variable argument empty, you will get a syntax error, because there will be an extra comma after the format string. -@example +@smallexample eprintf("success!\n", ); @expansion{} fprintf(stderr, "success!\n", ); -@end example +@end smallexample GNU CPP has a pair of extensions which deal with this problem. First, you are allowed to leave the variable argument out entirely: -@example +@smallexample eprintf ("success!\n") @expansion{} fprintf(stderr, "success!\n", ); -@end example +@end smallexample @noindent Second, the @samp{##} token paste operator has a special meaning when placed between a comma and a variable argument. If you write -@example +@smallexample #define eprintf(format, @dots{}) fprintf (stderr, format, ##__VA_ARGS__) -@end example +@end smallexample @noindent and the variable argument is left out when the @code{eprintf} macro is @@ -1665,10 +1716,19 @@ used, then the comma before the @samp{##} will be deleted. This does @emph{not} happen if you pass an empty argument, nor does it happen if the token preceding @samp{##} is anything other than a comma. -@example +@smallexample eprintf ("success!\n") @expansion{} fprintf(stderr, "success!\n"); -@end example +@end smallexample + +@noindent +The above explanation is ambiguous about the case where the only macro +parameter is a variable arguments parameter, as it is meaningless to +try to distinguish whether no argument at all is an empty argument or +a missing argument. In this case the C99 standard is clear that the +comma must remain, however the existing GCC extension used to swallow +the comma. So CPP retains the comma when conforming to a specific C +standard, and drops it otherwise. C99 mandates that the only place the identifier @code{@w{__VA_ARGS__}} can appear is in the replacement list of a variadic macro. It may not @@ -1685,16 +1745,16 @@ only named variable arguments. On the other hand, if you are concerned with portability to other conforming implementations of C99, you should use only @code{@w{__VA_ARGS__}}. -Previous versions of GNU CPP implemented the comma-deletion extension +Previous versions of 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 GCC, the token preceding the special @samp{##} must be a comma, and there must be white space between that comma and whatever comes immediately before it: -@example +@smallexample #define eprintf(format, args@dots{}) fprintf (stderr, format , ##args) -@end example +@end smallexample @noindent @xref{Differences from previous versions}, for the gory details. @@ -1721,7 +1781,7 @@ predefined macros, but you cannot undefine them. @subsection Standard Predefined Macros @cindex standard predefined macros. -The standard predefined macros are specified by the C and/or C++ +The standard predefined macros are specified by the relevant language standards, so they are available with all compilers that implement those standards. Older compilers may not provide all of them. Their names all start with double underscores. @@ -1747,12 +1807,12 @@ message to report an inconsistency detected by the program; the message can state the source line at which the inconsistency was detected. For example, -@example +@smallexample fprintf (stderr, "Internal error: " "negative string length " "%d at %s, line %d.", length, __FILE__, __LINE__); -@end example +@end smallexample An @samp{#include} directive changes the expansions of @code{__FILE__} and @code{__LINE__} to correspond to the included file. At the end of @@ -1780,29 +1840,35 @@ the preprocessor is being run. The string constant contains eleven characters and looks like @code{@w{"Feb 12 1996"}}. If the day of the month is less than 10, it is padded with a space on the left. +If GCC cannot determine the current date, it will emit a warning message +(once per compilation) and @code{__DATE__} will expand to +@code{@w{"??? ?? ????"}}. + @item __TIME__ This macro expands to a string constant that describes the time at which the preprocessor is being run. The string constant contains eight characters and looks like @code{"23:59:01"}. +If GCC cannot determine the current time, it will emit a warning message +(once per compilation) and @code{__TIME__} will expand to +@code{"??:??:??"}. + @item __STDC__ In normal operation, this macro expands to the constant 1, to signify that this compiler conforms to ISO Standard C@. If GNU CPP is used with a compiler other than GCC, this is not necessarily true; however, the -preprocessor always conforms to the standard, unless the -@option{-traditional} option is used. +preprocessor always conforms to the standard unless the +@option{-traditional-cpp} option is used. -This macro is not defined if the @option{-traditional} option is used. +This macro is not defined if the @option{-traditional-cpp} option is used. On some hosts, the system compiler uses a different convention, where @code{__STDC__} is normally 0, but is 1 if the user specifies strict -conformance to the C Standard. GNU CPP follows the host convention when +conformance to the C Standard. CPP follows the host convention when processing system header files, but when processing user files @code{__STDC__} is always 1. This has been reported to cause problems; for instance, some versions of Solaris provide X Windows headers that -expect @code{__STDC__} to be either undefined or 1. You may be able to -work around this sort of problem by using an @option{-I} option to -cancel treatment of those headers as system headers. @xref{Invocation}. +expect @code{__STDC__} to be either undefined or 1. @xref{Invocation}. @item __STDC_VERSION__ This macro expands to the C Standard's version number, a long integer @@ -1817,8 +1883,8 @@ The value @code{199409L} signifies the 1989 C standard as amended in the 1999 revision of the C standard. Support for the 1999 revision is not yet complete. -This macro is not defined if the @option{-traditional} option is used, nor -when compiling C++ or Objective-C@. +This macro is not defined if the @option{-traditional-cpp} option is +used, nor when compiling C++ or Objective-C@. @item __STDC_HOSTED__ This macro is defined, with value 1, if the compiler's target is a @@ -1832,7 +1898,17 @@ or a C++ compiler. This macro is similar to @code{__STDC_VERSION__}, in that it expands to a version number. A fully conforming implementation of the 1998 C++ standard will define this macro to @code{199711L}. The GNU C++ compiler is not yet fully conforming, so it uses @code{1} -instead. We hope to complete our implementation in the near future. +instead. It is hoped to complete the implementation of standard C++ +in the near future. + +@item __OBJC__ +This macro is defined, with value 1, when the Objective-C compiler is in +use. You can use @code{__OBJC__} to test whether a header is compiled +by a C compiler or a Objective-C compiler. + +@item __ASSEMBLER__ +This macro is defined with value 1 when preprocessing assembly +language. @end table @@ -1871,26 +1947,26 @@ minor version and patch level are reset. If you wish to use the predefined macros directly in the conditional, you will need to write it like this: -@example +@smallexample /* @r{Test for GCC > 3.2.0} */ #if __GNUC__ > 3 || \ (__GNUC__ == 3 && (__GNUC_MINOR__ > 2 || \ (__GNUC_MINOR__ == 2 && \ __GNUC_PATCHLEVEL__ > 0)) -@end example +@end smallexample @noindent Another approach is to use the predefined macros to calculate a single number, then compare that against a threshold: -@example +@smallexample #define GCC_VERSION (__GNUC__ * 10000 \ + __GNUC_MINOR__ * 100 \ + __GNUC_PATCHLEVEL__) @dots{} /* @r{Test for GCC > 3.2.0} */ #if GCC_VERSION > 30200 -@end example +@end smallexample @noindent Many people find this form easier to understand. @@ -1919,6 +1995,9 @@ incremented on every @samp{#include} directive and decremented at the end of every included file. It starts out at 0, it's value within the base file specified on the command line. +@item __ELF__ +This macro is defined if the target uses the ELF object format. + @item __VERSION__ This macro expands to a string constant which describes the version of the compiler in use. You should not rely on its contents having any @@ -1947,6 +2026,10 @@ unsigned on the target machine. It exists to cause the standard header file @file{limits.h} to work correctly. You should not use this macro yourself; instead, refer to the standard macros defined in @file{limits.h}. +@item __WCHAR_UNSIGNED__ +Like @code{__CHAR_UNSIGNED__}, this macro is defined if and only if the +data type @code{wchar_t} is unsigned and the front-end is in C++ mode. + @item __REGISTER_PREFIX__ This macro expands to a single token (not a string constant) which is the prefix applied to CPU register names in assembly language for this @@ -1977,6 +2060,41 @@ typedefs, respectively. They exist to make the standard header files these macros directly; instead, include the appropriate headers and use the typedefs. +@item __CHAR_BIT__ +Defined to the number of bits used in the representation of the +@code{char} data type. It exists to make the standard header given +numerical limits work correctly. You should not use +this macro directly; instead, include the appropriate headers. + +@item __SCHAR_MAX__ +@itemx __WCHAR_MAX__ +@itemx __SHRT_MAX__ +@itemx __INT_MAX__ +@itemx __LONG_MAX__ +@itemx __LONG_LONG_MAX__ +Defined to the maximum value of the @code{signed char}, @code{wchar_t}, +@code{signed short}, +@code{signed int}, @code{signed long}, and @code{signed long long} types +respectively. They exist to make the standard header given numerical limits +work correctly. You should not use these macros directly; instead, include +the appropriate headers. + +@item __USING_SJLJ_EXCEPTIONS__ +This macro is defined, with value 1, if the compiler uses the old +mechanism based on @code{setjmp} and @code{longjmp} for exception +handling. + +@item __NEXT_RUNTIME__ +This macro is defined, with value 1, if (and only if) the NeXT runtime +(as in @option{-fnext-runtime}) is in use for Objective-C. If the GNU +runtime is used, this macro is not defined, so that you can use this +macro to determine which runtime (NeXT or GNU) is being used. + +@item __LP64__ +@itemx _LP64 +These macros are defined, with value 1, if (and only if) the compilation +is for a target where @code{long int} and pointer both use 64-bits and +@code{int} uses 32-bit. @end table @node System-specific Predefined Macros @@ -2063,12 +2181,12 @@ macro is function-like. It is an error if anything appears on the line after the macro name. @samp{#undef} has no effect if the name is not a macro. -@example +@smallexample #define FOO 4 x = FOO; @expansion{} x = 4; #undef FOO x = FOO; @expansion{} x = FOO; -@end example +@end smallexample Once a macro has been undefined, that identifier may be @dfn{redefined} as a macro by a subsequent @samp{#define} directive. The new definition @@ -2088,19 +2206,19 @@ count as whitespace. @noindent These definitions are effectively the same: -@example +@smallexample #define FOUR (2 + 2) #define FOUR (2 + 2) #define FOUR (2 /* two */ + 2) -@end example +@end smallexample @noindent but these are not: -@example +@smallexample #define FOUR (2 + 2) #define FOUR ( 2+2 ) #define FOUR (2 * 2) #define FOUR(score,and,seven,years,ago) (2 + 2) -@end example +@end smallexample If a macro is redefined with a definition that is not effectively the same as the old one, the preprocessor issues a warning and changes the @@ -2109,6 +2227,50 @@ the same, the redefinition is silently ignored. This allows, for instance, two different headers to define a common macro. The preprocessor will only complain if the definitions do not match. +@node Directives Within Macro Arguments +@section Directives Within Macro Arguments +@cindex macro arguments and directives + +Occasionally it is convenient to use preprocessor directives within +the arguments of a macro. The C and C++ standards declare that +behavior in these cases is undefined. + +Versions of CPP prior to 3.2 would reject such constructs with an +error message. This was the only syntactic difference between normal +functions and function-like macros, so it seemed attractive to remove +this limitation, and people would often be surprised that they could +not use macros in this way. Moreover, sometimes people would use +conditional compilation in the argument list to a normal library +function like @samp{printf}, only to find that after a library upgrade +@samp{printf} had changed to be a function-like macro, and their code +would no longer compile. So from version 3.2 we changed CPP to +successfully process arbitrary directives within macro arguments in +exactly the same way as it would have processed the directive were the +function-like macro invocation not present. + +If, within a macro invocation, that macro is redefined, then the new +definition takes effect in time for argument pre-expansion, but the +original definition is still used for argument replacement. Here is a +pathological example: + +@smallexample +#define f(x) x x +f (1 +#undef f +#define f 2 +f) +@end smallexample + +@noindent +which expands to + +@smallexample +1 2 1 2 +@end smallexample + +@noindent +with the semantics described above. + @node Macro Pitfalls @section Macro Pitfalls @cindex problems with macros @@ -2137,25 +2299,25 @@ the input file, for more macro calls. It is possible to piece together a macro call coming partially from the macro body and partially from the arguments. For example, -@example +@smallexample #define twice(x) (2*(x)) #define call_with_1(x) x(1) call_with_1 (twice) @expansion{} twice(1) @expansion{} (2*(1)) -@end example +@end smallexample Macro definitions do not have to have balanced parentheses. By writing an unbalanced open parenthesis in a macro body, it is possible to create a macro call that begins inside the macro body but ends outside of it. For example, -@example +@smallexample #define strange(file) fprintf (file, "%s %d", @dots{} strange(stderr) p, 35) @expansion{} fprintf (stderr, "%s %d", p, 35) -@end example +@end smallexample The ability to piece together a macro call can be useful, but the use of unbalanced open parentheses in a macro body is just confusing, and @@ -2173,41 +2335,41 @@ way. Suppose you define a macro as follows, -@example +@smallexample #define ceil_div(x, y) (x + y - 1) / y -@end example +@end smallexample @noindent whose purpose is to divide, rounding up. (One use for this operation is to compute how many @code{int} objects are needed to hold a certain number of @code{char} objects.) Then suppose it is used as follows: -@example +@smallexample a = ceil_div (b & c, sizeof (int)); @expansion{} a = (b & c + sizeof (int) - 1) / sizeof (int); -@end example +@end smallexample @noindent This does not do what is intended. The operator-precedence rules of C make it equivalent to this: -@example +@smallexample a = (b & (c + sizeof (int) - 1)) / sizeof (int); -@end example +@end smallexample @noindent What we want is this: -@example +@smallexample a = ((b & c) + sizeof (int) - 1)) / sizeof (int); -@end example +@end smallexample @noindent Defining the macro as -@example +@smallexample #define ceil_div(x, y) ((x) + (y) - 1) / (y) -@end example +@end smallexample @noindent provides the desired result. @@ -2217,9 +2379,9 @@ ceil_div(1, 2)}. That has the appearance of a C expression that would compute the size of the type of @code{ceil_div (1, 2)}, but in fact it means something very different. Here is what it expands to: -@example +@smallexample sizeof ((1) + (2) - 1) / (2) -@end example +@end smallexample @noindent This would take the size of an integer and divide it by two. The @@ -2229,9 +2391,9 @@ was intended to be inside. Parentheses around the entire macro definition prevent such problems. Here, then, is the recommended way to define @code{ceil_div}: -@example +@smallexample #define ceil_div(x, y) (((x) + (y) - 1) / (y)) -@end example +@end smallexample @node Swallowing the Semicolon @subsection Swallowing the Semicolon @@ -2242,13 +2404,13 @@ statement. Consider, for example, the following macro, that advances a pointer (the argument @code{p} says where to find it) across whitespace characters: -@example +@smallexample #define SKIP_SPACES(p, limit) \ @{ char *lim = (limit); \ while (p < lim) @{ \ if (*p++ != ' ') @{ \ p--; break; @}@}@} -@end example +@end smallexample @noindent Here backslash-newline is used to split the macro definition, which must @@ -2265,11 +2427,11 @@ like a function call, writing a semicolon afterward, as in This can cause trouble before @code{else} statements, because the semicolon is actually a null statement. Suppose you write -@example +@smallexample if (*p != 0) SKIP_SPACES (p, lim); else @dots{} -@end example +@end smallexample @noindent The presence of two statements---the compound statement and a null @@ -2279,20 +2441,20 @@ makes invalid C code. The definition of the macro @code{SKIP_SPACES} can be altered to solve this problem, using a @code{do @dots{} while} statement. Here is how: -@example +@smallexample #define SKIP_SPACES(p, limit) \ do @{ char *lim = (limit); \ while (p < lim) @{ \ if (*p++ != ' ') @{ \ p--; break; @}@}@} \ while (0) -@end example +@end smallexample Now @code{SKIP_SPACES (p, lim);} expands into -@example +@smallexample do @{@dots{}@} while (0); -@end example +@end smallexample @noindent which is one statement. The loop executes exactly once; most compilers @@ -2305,23 +2467,23 @@ generate no extra code for it. @cindex unsafe macros Many C programs define a macro @code{min}, for ``minimum'', like this: -@example +@smallexample #define min(X, Y) ((X) < (Y) ? (X) : (Y)) -@end example +@end smallexample When you use this macro with an argument containing a side effect, as shown here, -@example +@smallexample next = min (x + y, foo (z)); -@end example +@end smallexample @noindent it expands as follows: -@example +@smallexample next = ((x + y) < (foo (z)) ? (x + y) : (foo (z))); -@end example +@end smallexample @noindent where @code{x + y} has been substituted for @code{X} and @code{foo (z)} @@ -2339,12 +2501,12 @@ computes the value of @code{foo (z)} only once. The C language offers no standard way to do this, but it can be done with GNU extensions as follows: -@example +@smallexample #define min(X, Y) \ (@{ typeof (X) x_ = (X); \ typeof (Y) y_ = (Y); \ (x_ < y_) ? x_ : y_; @}) -@end example +@end smallexample The @samp{(@{ @dots{} @})} notation produces a compound statement that acts as an expression. Its value is the value of its last statement. @@ -2358,7 +2520,7 @@ careful when @emph{using} the macro @code{min}. For example, you can calculate the value of @code{foo (z)}, save it in a variable, and use that variable in @code{min}: -@example +@smallexample @group #define min(X, Y) ((X) < (Y) ? (X) : (Y)) @dots{} @@ -2367,7 +2529,7 @@ that variable in @code{min}: next = min (x + y, tem); @} @end group -@end example +@end smallexample @noindent (where we assume that @code{foo} returns type @code{int}). @@ -2381,11 +2543,11 @@ definition. Recall that all macro definitions are rescanned for more macros to replace. If the self-reference were considered a use of the macro, it would produce an infinitely large expansion. To prevent this, the self-reference is not considered a macro call. It is passed into -the preprocessor output unchanged. Let's consider an example: +the preprocessor output unchanged. Consider an example: -@example +@smallexample #define foo (4 + foo) -@end example +@end smallexample @noindent where @code{foo} is also a variable in your program. @@ -2408,9 +2570,9 @@ of the variable @code{foo}, whereas in fact the value is four greater. One common, useful use of self-reference is to create a macro which expands to itself. If you write -@example +@smallexample #define EPERM EPERM -@end example +@end smallexample @noindent then the macro @code{EPERM} expands to @code{EPERM}. Effectively, it is @@ -2424,15 +2586,15 @@ If a macro @code{x} expands to use a macro @code{y}, and the expansion of self-reference} of @code{x}. @code{x} is not expanded in this case either. Thus, if we have -@example +@smallexample #define x (4 + y) #define y (2 * x) -@end example +@end smallexample @noindent then @code{x} and @code{y} expand as follows: -@example +@smallexample @group x @expansion{} (4 + y) @expansion{} (4 + (2 * x)) @@ -2440,7 +2602,7 @@ x @expansion{} (4 + y) y @expansion{} (2 * x) @expansion{} (2 * (4 + y)) @end group -@end example +@end smallexample @noindent Each macro is expanded when it appears in the definition of the other @@ -2501,12 +2663,12 @@ concatenate its expansion, you can do that by causing one macro to call another macro that does the stringification or concatenation. For instance, if you have -@example +@smallexample #define AFTERX(x) X_ ## x #define XAFTERX(x) AFTERX(x) #define TABLESIZE 1024 #define BUFSIZE TABLESIZE -@end example +@end smallexample then @code{AFTERX(BUFSIZE)} expands to @code{X_BUFSIZE}, and @code{XAFTERX(BUFSIZE)} expands to @code{X_1024}. (Not to @@ -2518,11 +2680,11 @@ Macros used in arguments, whose expansions contain unshielded commas. This can cause a macro expanded on the second scan to be called with the wrong number of arguments. Here is an example: -@example +@smallexample #define foo a,b #define bar(x) lose(x) #define lose(x) (1 + (x)) -@end example +@end smallexample We would like @code{bar(foo)} to turn into @code{(1 + (foo))}, which would then turn into @code{(1 + (a,b))}. Instead, @code{bar(foo)} @@ -2531,11 +2693,11 @@ requires a single argument. In this case, the problem is easily solved by the same parentheses that ought to be used to prevent misnesting of arithmetic operations: -@example +@smallexample #define foo (a,b) @exdent or #define bar(x) lose((x)) -@end example +@end smallexample The extra pair of parentheses prevents the comma in @code{foo}'s definition from being interpreted as an argument separator. @@ -2554,13 +2716,13 @@ different to the line containing the argument causing the problem. Here is an example illustrating this: -@example +@smallexample #define ignore_second_arg(a,b,c) a; c ignore_second_arg (foo (), ignored (), syntax error); -@end example +@end smallexample @noindent The syntax error triggered by the tokens @code{syntax error} results in @@ -2661,7 +2823,7 @@ directive}: @samp{#if}, @samp{#ifdef} or @samp{#ifndef}. The simplest sort of conditional is -@example +@smallexample @group #ifdef @var{MACRO} @@ -2669,7 +2831,7 @@ The simplest sort of conditional is #endif /* @var{MACRO} */ @end group -@end example +@end smallexample @cindex conditional group This block is called a @dfn{conditional group}. @var{controlled text} @@ -2696,7 +2858,7 @@ good practice if there is a lot of @var{controlled text}, because it helps people match the @samp{#endif} to the corresponding @samp{#ifdef}. Older programs sometimes put @var{MACRO} directly after the @samp{#endif} without enclosing it in a comment. This is invalid code -according to the C standard. GNU CPP accepts it with a warning. It +according to the C standard. CPP accepts it with a warning. It never affects which @samp{#ifndef} the @samp{#endif} matches. @findex #ifndef @@ -2742,7 +2904,7 @@ automated by a tool such as @command{autoconf}, or done by hand. The @samp{#if} directive allows you to test the value of an arithmetic expression, rather than the mere existence of one macro. Its syntax is -@example +@smallexample @group #if @var{expression} @@ -2750,7 +2912,7 @@ expression, rather than the mere existence of one macro. Its syntax is #endif /* @var{expression} */ @end group -@end example +@end smallexample @var{expression} is a C expression of integer type, subject to stringent restrictions. It may contain @@ -2803,9 +2965,6 @@ expression, and may give different results in some cases. If the value comes out to be nonzero, the @samp{#if} succeeds and the @var{controlled text} is included; otherwise it is skipped. -If @var{expression} is not correctly formed, GCC issues an error and -treats the conditional as having failed. - @node Defined @subsection Defined @@ -2820,9 +2979,9 @@ defined MACRO}} is precisely equivalent to @code{@w{#ifdef MACRO}}. @code{defined} is useful when you wish to test more than one macro for existence at once. For example, -@example +@smallexample #if defined (__vax__) || defined (__ns16000__) -@end example +@end smallexample @noindent would succeed if either of the names @code{__vax__} or @@ -2830,9 +2989,9 @@ would succeed if either of the names @code{__vax__} or Conditionals written like this: -@example +@smallexample #if defined BUFSIZE && BUFSIZE >= 1024 -@end example +@end smallexample @noindent can generally be simplified to just @code{@w{#if BUFSIZE >= 1024}}, @@ -2853,7 +3012,7 @@ The @samp{#else} directive can be added to a conditional to provide alternative text to be used if the condition fails. This is what it looks like: -@example +@smallexample @group #if @var{expression} @var{text-if-true} @@ -2861,7 +3020,7 @@ looks like: @var{text-if-false} #endif /* Not @var{expression} */ @end group -@end example +@end smallexample @noindent If @var{expression} is nonzero, the @var{text-if-true} is included and @@ -2877,7 +3036,7 @@ You can use @samp{#else} with @samp{#ifdef} and @samp{#ifndef}, too. One common case of nested conditionals is used to check for more than two possible alternatives. For example, you might have -@example +@smallexample #if X == 1 @dots{} #else /* X != 1 */ @@ -2887,12 +3046,12 @@ possible alternatives. For example, you might have @dots{} #endif /* X != 2 */ #endif /* X != 1 */ -@end example +@end smallexample Another conditional directive, @samp{#elif}, allows this to be abbreviated as follows: -@example +@smallexample #if X == 1 @dots{} #elif X == 2 @@ -2900,7 +3059,7 @@ abbreviated as follows: #else /* X != 2 and X != 1*/ @dots{} #endif /* X != 2 and X != 1*/ -@end example +@end smallexample @samp{#elif} stands for ``else if''. Like @samp{#else}, it goes in the middle of a conditional group and subdivides it; it does not require a @@ -2929,7 +3088,7 @@ syntax errors. One way to avoid this problem is to use an always-false conditional instead. For instance, put @code{#if 0} before the deleted code and -@code{#endif} after it. This This works even if the code being turned +@code{#endif} after it. This works even if the code being turned off contains conditionals, but they must be entire conditionals (balanced @samp{#if} and @samp{#endif}). @@ -2960,23 +3119,23 @@ combination of parameters which you know the program does not properly support. For example, if you know that the program will not run properly on a VAX, you might write -@example +@smallexample @group #ifdef __vax__ #error "Won't work on VAXen. See comments at get_last_object." #endif @end group -@end example +@end smallexample If you have several configuration parameters that must be set up by the installation in a consistent way, you can use conditionals to detect an inconsistency and report it with @samp{#error}. For example, -@example +@smallexample #if !defined(UNALIGNED_INT_ASM_OP) && defined(DWARF2_DEBUGGING_INFO) #error "DWARF2_DEBUGGING_INFO requires UNALIGNED_INT_ASM_OP." #endif -@end example +@end smallexample @findex #warning The directive @samp{#warning} is like @samp{#error}, but causes the @@ -3028,6 +3187,13 @@ input. Subsequent lines are counted from @var{linenum}. effect. In addition, @var{filename} is a string constant. The following line and all subsequent lines are reported to come from the file it specifies, until something else happens to change that. +@var{filename} is interpreted according to the normal rules for a string +constant: backslash escapes are interpreted. This is different from +@samp{#include}. + +Previous versions of CPP did not interpret escapes in @samp{#line}; +we have changed it because the standard requires they be interpreted, +and most other compilers do. @item #line @var{anything else} @var{anything else} is checked for macro calls, which are expanded. @@ -3037,7 +3203,35 @@ The result should match one of the above two forms. @samp{#line} directives alter the results of the @code{__FILE__} and @code{__LINE__} predefined macros from that point on. @xref{Standard Predefined Macros}. They do not have any effect on @samp{#include}'s -idea of the directory containing the current file. +idea of the directory containing the current file. This is a change +from GCC 2.95. Previously, a file reading + +@smallexample +#line 1 "../src/gram.y" +#include "gram.h" +@end smallexample + +would search for @file{gram.h} in @file{../src}, then the @option{-I} +chain; the directory containing the physical source file would not be +searched. In GCC 3.0 and later, the @samp{#include} is not affected by +the presence of a @samp{#line} referring to a different directory. + +We made this change because the old behavior caused problems when +generated source files were transported between machines. For instance, +it is common practice to ship generated parsers with a source release, +so that people building the distribution do not need to have yacc or +Bison installed. These files frequently have @samp{#line} directives +referring to the directory tree of the system where the 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 it attempts to include a header +which would be visible searching from the directory containing the +source file. However, this problem is easily solved with an additional +@option{-I} switch on the command line. The failures caused by the old +semantics could sometimes be corrected only by editing the generated +files, which is difficult and error-prone. @node Pragmas @chapter Pragmas @@ -3075,18 +3269,18 @@ literal. It is destringized, by replacing all @samp{\\} with a single processed as if it had appeared as the right hand side of a @samp{#pragma} directive. For example, -@example +@smallexample _Pragma ("GCC dependency \"parse.y\"") -@end example +@end smallexample @noindent has the same effect as @code{#pragma GCC dependency "parse.y"}. The same effect could be achieved using macros, for example -@example +@smallexample #define DO_PRAGMA(x) _Pragma (#x) DO_PRAGMA (GCC dependency "parse.y") -@end example +@end smallexample The standard is unclear on where a @code{_Pragma} operator can appear. The preprocessor does not accept it within a preprocessing conditional @@ -3108,10 +3302,10 @@ other file is searched for using the normal include search path. Optional trailing text can be used to give more information in the warning message. -@example +@smallexample #pragma GCC dependency "parse.y" #pragma GCC dependency "/usr/include/time.h" rerun fixincludes -@end example +@end smallexample @item #pragma GCC poison Sometimes, there is an identifier that you want to remove completely @@ -3121,10 +3315,10 @@ enforce this, you can @dfn{poison} the identifier with this pragma. poison. If any of those identifiers appears anywhere in the source after the directive, it is a hard error. For example, -@example +@smallexample #pragma GCC poison printf sprintf fprintf sprintf(some_string, "hello"); -@end example +@end smallexample @noindent will produce an error. @@ -3136,11 +3330,11 @@ about system headers defining macros that use it. For example, -@example +@smallexample #define strrchr rindex #pragma GCC poison rindex strrchr(some_string, 'h'); -@end example +@end smallexample @noindent will not produce an error. @@ -3164,8 +3358,8 @@ This directive is not part of the C standard, but it is not an official GNU extension either. We believe it came from System V@. @findex #sccs -The @samp{#sccs} directive is recognized on some systems, because it -appears in their header files. It is a very old, obscure, extension +The @samp{#sccs} directive is recognized, because it appears in the +header files of some systems. It is a very old, obscure, extension which we did not invent, and we have been unable to find any documentation of what it should do, so GCC simply ignores it. @@ -3199,7 +3393,7 @@ preprocessor preserves whitespace between tokens, or replaces it with e.g.@: a single space. In GNU CPP, whitespace between tokens is collapsed to become a single space, with the exception that the first token on a non-directive line is preceded with sufficient spaces that it appears in -the same column in the preprocessed output that it appeared in in the +the same column in the preprocessed output that it appeared in the original source file. This is so the output is easy to read. @xref{Differences from previous versions}. CPP does not insert any whitespace where there was none in the original source, except where @@ -3209,15 +3403,16 @@ necessary to prevent an accidental token paste. Source file name and line number information is conveyed by lines of the form -@example +@smallexample # @var{linenum} @var{filename} @var{flags} -@end example +@end smallexample @noindent These are called @dfn{linemarkers}. They are inserted as needed into the output (but never within a string or character constant). They mean that the following line originated in file @var{filename} at line -@var{linenum}. +@var{linenum}. @var{filename} will never contain any non-printing +characters; they are replaced with octal escape sequences. After the file name comes zero or more flags, which are @samp{1}, @samp{2}, @samp{3}, or @samp{4}. If there are multiple flags, spaces @@ -3258,91 +3453,230 @@ the directive name. Traditional (pre-standard) C preprocessing is rather different from the preprocessing specified by the standard. When GCC is given the -@option{-traditional} option, it attempts to emulate a traditional -preprocessor. We do not guarantee that GCC's behavior under -@option{-traditional} matches any pre-standard preprocessor exactly. +@option{-traditional-cpp} option, it attempts to emulate a traditional +preprocessor. -Traditional mode exists only for backward compatibility. We have no -plans to augment it in any way nor will we change it except to fix -catastrophic bugs. You should be aware that modern C libraries often -have header files which are incompatible with traditional mode. +GCC versions 3.2 and later only support traditional mode semantics in +the preprocessor, and not in the compiler front ends. This chapter +outlines the traditional preprocessor semantics we implemented. -This is a list of the differences. It may not be complete, and may not -correspond exactly to the behavior of either GCC or a true traditional -preprocessor. +The implementation does not correspond precisely to the behavior of +earlier versions of GCC, nor to any true traditional preprocessor. +After all, inconsistencies among traditional implementations were a +major motivation for C standardization. However, we intend that it +should be compatible with true traditional preprocessors in all ways +that actually matter. -@itemize @bullet -@item -Traditional macro expansion pays no attention to single-quote or -double-quote characters; macro argument symbols are replaced by the -argument values even when they appear within apparent string or -character constants. +@menu +* Traditional lexical analysis:: +* Traditional macros:: +* Traditional miscellany:: +* Traditional warnings:: +@end menu -@item -Traditionally, it is permissible for a macro expansion to end in the -middle of a string or character constant. The constant continues into -the text surrounding the macro call. +@node Traditional lexical analysis +@section Traditional lexical analysis -@item -However, the end of the line terminates a string or character constant, -with no error. (This is a kluge. Traditional mode is commonly used to -preprocess things which are not C, and have a different comment syntax. -Single apostrophes often appear in comments. This kluge prevents the -traditional preprocessor from issuing errors on such comments.) +The traditional preprocessor does not decompose its input into tokens +the same way a standards-conforming preprocessor does. The input is +simply treated as a stream of text with minimal internal form. -@item -Preprocessing directives are recognized in traditional C only when their -leading @samp{#} appears in the first column. There can be no -whitespace between the beginning of the line and the @samp{#}. +This implementation does not treat trigraphs (@pxref{trigraphs}) +specially since they were an invention of the standards committee. It +handles arbitrarily-positioned escaped newlines properly and splices +the lines as you would expect; many traditional preprocessors did not +do this. -@item -In traditional C, a comment is equivalent to no text at all. (In ISO -C, a comment counts as whitespace.) It can be used sort of the same way -that @samp{##} is used in ISO C, to paste macro arguments together. +The form of horizontal whitespace in the input file is preserved in +the output. In particular, hard tabs remain hard tabs. This can be +useful if, for example, you are preprocessing a Makefile. -@item -Traditional C does not have the concept of a preprocessing number. +Traditional CPP only recognizes C-style block comments, and treats the +@samp{/*} sequence as introducing a comment only if it lies outside +quoted text. Quoted text is introduced by the usual single and double +quotes, and also by an initial @samp{<} in a @code{#include} +directive. -@item -A macro is not suppressed within its own definition, in traditional C@. -Thus, any macro that is used recursively inevitably causes an error. +Traditionally, comments are completely removed and are not replaced +with a space. Since a traditional compiler does its own tokenization +of the output of the preprocessor, this means that comments can +effectively be used as token paste operators. However, comments +behave like separators for text handled by the preprocessor itself, +since it doesn't re-lex its input. For example, in -@item -The @samp{#} and @samp{##} operators are not available in traditional -C@. +@smallexample +#if foo/**/bar +@end smallexample + +@noindent +@samp{foo} and @samp{bar} are distinct identifiers and expanded +separately if they happen to be macros. In other words, this +directive is equivalent to + +@smallexample +#if foo bar +@end smallexample + +@noindent +rather than + +@smallexample +#if foobar +@end smallexample + +Generally speaking, in traditional mode an opening quote need not have +a matching closing quote. In particular, a macro may be defined with +replacement text that contains an unmatched quote. Of course, if you +attempt to compile preprocessed output containing an unmatched quote +you will get a syntax error. + +However, all preprocessing directives other than @code{#define} +require matching quotes. For example: + +@smallexample +#define m This macro's fine and has an unmatched quote +"/* This is not a comment. */ +/* This is a comment. The following #include directive + is ill-formed. */ +#include }} -are omitted. - -@item -MF @var{file} -When used with @option{-M} or @option{-MM}, specifies a file to write the -dependencies to. This allows the preprocessor to write the preprocessed -file to stdout normally. If no @option{-MF} switch is given, CPP sends -the rules to stdout and suppresses normal preprocessed output. - -@item -MG -When used with @option{-M} or @option{-MM}, @option{-MG} says to treat missing -header files as generated files and assume they live in the same -directory as the source file. It suppresses preprocessed output, as a -missing header file is ordinarily an error. - -This feature is used in automatic updating of makefiles. - -@item -MP -This option instructs CPP to add a phony target for each dependency -other than the main file, causing each to depend on nothing. These -dummy rules work around errors @command{make} gives if you remove header -files without updating the @file{Makefile} to match. - -This is typical output: - -@example -test.o: test.c test.h - -test.h: -@end example - -@item -MT @var{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 @samp{.c}, and appends the platform's -usual object suffix. The result is the target. - -An @option{-MT} option will set the target to be exactly the string you -specify. If you want multiple targets, you can specify them as a single -argument to @option{-MT}, or use multiple @option{-MT} options. - -For example, @option{@w{-MT '$(objpfx)foo.o'}} might give - -@example -$(objpfx)foo.o: foo.c -@end example - -@item -MQ @var{target} - -Same as @option{-MT}, but it quotes any characters which are special to -Make. @option{@w{-MQ '$(objpfx)foo.o'}} gives - -@example -$$(objpfx)foo.o: foo.c -@end example - -The default target is automatically quoted, as if it were given with -@option{-MQ}. - -@item -MD @var{file} -@itemx -MMD @var{file} -@option{-MD @var{file}} is equivalent to @option{-M -MF @var{file}}, and -@option{-MMD @var{file}} is equivalent to @option{-MM -MF @var{file}}. - -Due to limitations in the compiler driver, you must use these switches -when you want to generate a dependency file as a side-effect of normal -compilation. - -@item -x c -@itemx -x c++ -@itemx -x objective-c -@itemx -x assembler-with-cpp -Specify the source language: C, C++, Objective-C, or assembly. This has -nothing to do with standards conformance or extensions; it merely -selects which base syntax to expect. If you give none of these options, -cpp will deduce the language from the extension of the source file: -@samp{.c}, @samp{.cc}, @samp{.m}, or @samp{.S}. Some other common -extensions for C++ and assembly are also recognized. If cpp does not -recognize the extension, it will treat the file as C; this is the most -generic mode. - -@strong{Note:} Previous versions of cpp accepted a @option{-lang} option -which selected both the language and the standards conformance level. -This option has been removed, because it conflicts with the @option{-l} -option. - -@item -std=@var{standard} -@itemx -ansi -Specify the standard to which the code should conform. Currently cpp -only knows about the standards for C; other language standards will be -added in the future. - -@var{standard} -may be one of: -@table @code -@item iso9899:1990 -@itemx c89 -The ISO C standard from 1990. @samp{c89} is the customary shorthand for -this version of the standard. - -The @option{-ansi} option is equivalent to @option{-std=c89}. - -@item iso9899:199409 -The 1990 C standard, as amended in 1994. - -@item iso9899:1999 -@itemx c99 -@itemx iso9899:199x -@itemx c9x -The revised ISO C standard, published in December 1999. Before -publication, this was known as C9X@. - -@item gnu89 -The 1990 C standard plus GNU extensions. This is the default. - -@item gnu99 -@itemx gnu9x -The 1999 C standard plus GNU extensions. -@end table - -@item -I- -Split the include path. Any directories specified with @option{-I} -options before @option{-I-} are searched only for headers requested with -@code{@w{#include "@var{file}"}}; they are not searched for -@code{@w{#include <@var{file}>}}. If additional directories are -specified with @option{-I} options after the @option{-I-}, those -directories are searched for all @samp{#include} directives. - -In addition, @option{-I-} inhibits the use of the directory of the current -file directory as the first search directory for @code{@w{#include -"@var{file}"}}. @xref{Search Path}. - -@item -nostdinc -Do not search the standard system directories for header files. -Only the directories you have specified with @option{-I} options -(and the directory of the current file, if appropriate) are searched. - -@item -nostdinc++ -Do not search for header files in the C++-specific standard directories, -but do still search the other standard directories. (This option is -used when building the C++ library.) - -@item -include @var{file} - -Process @var{file} as if @code{#include "file"} appeared as the first -line of the primary source file. However, the first directory searched -for @var{file} is the preprocessor's working directory @emph{instead of} -the directory containing the main source file. If not found there, it -is searched for in the remainder of the @code{#include "@dots{}"} search -chain as normal. - -If multiple @option{-include} options are given, the files are included -in the order they appear on the command line. - -@item -imacros @var{file} - -Exactly like @option{-include}, except that any output produced by -scanning @var{file} is thrown away. Macros it defines remain defined. -This allows you to acquire all the macros from a header without also -processing its declarations. - -All files specified by @option{-imacros} are processed before all files -specified by @option{-include}. - -@item -idirafter @var{dir} -Search @var{dir} for header files, but do it @emph{after} all -directories specified with @option{-I} and the standard system directories -have been exhausted. @var{dir} is treated as a system include directory. - -@item -iprefix @var{prefix} -Specify @var{prefix} as the prefix for subsequent @option{-iwithprefix} -options. If the prefix represents a directory, you should include the -final @samp{/}. - -@item -iwithprefix @var{dir} -@itemx -iwithprefixbefore @var{dir} - -Append @var{dir} to the prefix specified previously with -@option{-iprefix}, and add the resulting directory to the include search -path. @option{-iwithprefixbefore} puts it in the same place @option{-I} -would; @option{-iwithprefix} puts it where @option{-idirafter} would. - -Use of these options is discouraged. - -@item -isystem @var{dir} -Search @var{dir} for header files, after all directories specified by -@option{-I} but before the standard system directories. Mark it -as a system directory, so that it gets the same special treatment as -is applied to the standard system directories. @xref{System Headers}. - -@item -fpreprocessed -Indicate to the preprocessor that the input file has already been -preprocessed. This suppresses things like macro expansion, trigraph -conversion, escaped newline splicing, and processing of most directives. -The preprocessor still recognizes and removes comments, so that you can -pass a file preprocessed with @option{-C} to the compiler without -problems. In this mode the integrated preprocessor is little more than -a tokenizer for the front ends. - -@option{-fpreprocessed} is implicit if the input file has one of the -extensions @samp{.i}, @samp{.ii} or @samp{.mi}. These are the -extensions that GCC uses for preprocessed files created by -@option{-save-temps}. - -@item -ftabstop=@var{width} -Set the distance between tab stops. This helps the preprocessor report -correct column numbers in warnings or errors, even if tabs appear on the -line. If the value is less than 1 or greater than 100, the option is -ignored. The default is 8. - -@item -fno-show-column -Do not print column numbers in diagnostics. This may be necessary if -diagnostics are being scanned by a program that does not understand the -column numbers, such as @command{dejagnu}. - -@item -A @var{predicate}=@var{answer} -Make an assertion with the predicate @var{predicate} and answer -@var{answer}. This form is preferred to the older form @option{-A -@var{predicate}(@var{answer})}, which is still supported, because -it does not use shell special characters. @xref{Assertions}. - -@item -A -@var{predicate}=@var{answer} -Cancel an assertion with the predicate @var{predicate} and answer -@var{answer}. - -@item -A- -Cancel all predefined assertions and all assertions preceding it on -the command line. Also, undefine all predefined macros and all -macros preceding it on the command line. (This is a historical wart and -may change in the future.) - -@item -dCHARS -@var{CHARS} is a sequence of one or more of the following characters, -and must not be preceded by a space. Other characters are interpreted -by the compiler proper, or reserved for future versions of GCC, and so -are silently ignored. If you specify characters whose behavior -conflicts, the result is undefined. - -@table @samp -@item M -Instead of the normal output, generate a list of @samp{#define} -directives for all the macros defined during the execution of the -preprocessor, including predefined macros. This gives you a way of -finding out what is predefined in your version of the preprocessor. -Assuming you have no file @file{foo.h}, the command - -@example -touch foo.h; cpp -dM foo.h -@end example - -@noindent -will show all the predefined macros. +@include cppopts.texi +@c man end -@item D -Like @samp{M} except in two respects: it does @emph{not} include the -predefined macros, and it outputs @emph{both} the @samp{#define} -directives and the result of preprocessing. Both kinds of output go to -the standard output file. +@node Environment Variables +@chapter Environment Variables +@cindex environment variables +@c man begin ENVIRONMENT -@item N -Like @samp{D}, but emit only the macro names, not their expansions. +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. -@item I -Output @samp{#include} directives in addition to the result of -preprocessing. -@end table +Note that you can also specify places to search using options such as +@option{-I}, and control dependency output with options like +@option{-M} (@pxref{Invocation}). These take precedence over +environment variables, which in turn take precedence over the +configuration of GCC@. -@item -P -Inhibit generation of linemarkers in the output from the preprocessor. -This might be useful when running the preprocessor on something that is -not C code, and will be sent to a program which might be confused by the -linemarkers. @xref{Preprocessor Output}. - -@item -C -Do not discard comments. All comments are passed through to the output -file, except for comments in processed directives, which are deleted -along with the directive. - -You should be prepared for side effects when using @option{-C}; it -causes the preprocessor to treat comments as tokens in their own right. -For example, comments appearing at the start of what would be a -directive line have the effect of turning that line into an ordinary -source line, since the first token on the line is no longer a @samp{#}. - -@item -gcc -Define the macros @sc{__gnuc__}, @sc{__gnuc_minor__} and -@sc{__gnuc_patchlevel__}. These are defined automatically when you use -@command{gcc -E}; you can turn them off in that case with -@option{-no-gcc}. - -@item -traditional -Try to imitate the behavior of old-fashioned C, as opposed to ISO -C@. @xref{Traditional Mode}. - -@item -trigraphs -Process trigraph sequences. @xref{Initial processing}. - -@item -remap -Enable special code to work around file systems which only permit very -short file names, such as MS-DOS@. - -@item -$ -Forbid the use of @samp{$} in identifiers. The C standard allows -implementations to define extra characters that can appear in -identifiers. By default GNU CPP permits @samp{$}, a common extension. - -@item -h -@itemx --help -@itemx --target-help -Print text describing all the command line options instead of -preprocessing anything. - -@item -v -Verbose mode. Print out GNU CPP's version number at the beginning of -execution, and report the final form of the include path. - -@item -H -Print the name of each header file used, in addition to other normal -activities. Each name is indented to show how deep in the -@samp{#include} stack it is. - -@item -version -@itemx --version -Print out GNU CPP's version number. With one dash, proceed to -preprocess as normal. With two dashes, exit immediately. -@end table +@include cppenv.texi @c man end @page +@include fdl.texi + +@page @node Index of Directives @unnumbered Index of Directives @printindex fn +@node Option Index +@unnumbered Option Index +@noindent +CPP's command line options and environment variables are indexed here +without any initial @samp{-} or @samp{--}. +@printindex op + +@page @node Concept Index @unnumbered Concept Index @printindex cp