@c @cropmarks
@c @finalout
+@include gcc-common.texi
+
@copying
@c man begin COPYRIGHT
Copyright @copyright{} 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996,
-1997, 1998, 1999, 2000, 2001, 2002, 2003
+1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
+2008, 2009, 2010, 2011
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
+under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation. A copy of
the license is included in the
@c man end
@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
@set cppmanual
@ifinfo
-@dircategory Programming
+@dircategory Software development
@direntry
-* Cpp: (cpp). The GNU C preprocessor.
+* Cpp: (cpp). The GNU C preprocessor.
@end direntry
@end ifinfo
@titlepage
@title The C Preprocessor
-@subtitle Last revised April 2001
-@subtitle for GCC version 3
-@author Richard M. Stallman
-@author Zachary Weinberg
+@versionsubtitle
+@author Richard M. Stallman, Zachary Weinberg
@page
@c There is a fill at the bottom of the page, so we need a filll to
@c override it.
* Include Operation::
* Search Path::
* Once-Only Headers::
+* Alternatives to Wrapper #ifndef::
* Computed Includes::
* Wrapper Headers::
* System Headers::
Obsolete Features
-* Assertions::
-* Obsolete once-only headers::
+* Obsolete Features::
@end detailmenu
@end menu
few things required by the standard. These are features which are
rarely, if ever, used, and may cause surprising changes to the meaning
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
+you should use the @option{-std=c90}, @option{-std=c99} or
+@option{-std=c1x} options, depending
on which version of the standard you want. To get all the mandatory
diagnostics, you must also use @option{-pedantic}. @xref{Invocation}.
Mode}.
For clarity, unless noted otherwise, references to @samp{CPP} in this
-manual refer to GNU CPP.
+manual refer to GNU CPP@.
@c man end
@menu
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.
+The character sets of the input files are specified using the
+@option{-finput-charset=} option.
All preprocessing work (the subject of the rest of this manual) is
carried out in the source character set. If you request textual
converted to the execution character set, just like unescaped
characters.
+Unless the experimental @option{-fextended-identifiers} option is used,
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.
+@samp{\u} and @samp{\U} escapes, in identifiers. Even with that
+option, characters outside the ASCII range can only be specified with
+the @samp{\u} and @samp{\U} escapes, not used directly in identifiers.
@node Initial processing
@section Initial processing
The nine trigraphs and their replacements are
-@example
+@smallexample
Trigraph: ??( ??) ??< ??> ??= ??/ ??' ??! ??-
Replacement: [ ] @{ @} # \ ^ | ~
-@end example
+@end smallexample
@item
@cindex continued lines
@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}
// @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.
+Comments are not recognized within string literals.
@t{@w{"/* blah */"}} is the string constant @samp{@w{/* blah */}}, not
an empty string.
@samp{*/}, and @samp{//} onto multiple lines with backslash-newline.
For example:
-@example
+@smallexample
@group
/\
*
O 10\
20
@end group
-@end example
+@end smallexample
@noindent
is equivalent to @code{@w{#define FOO 1020}}. All these tricks are
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
@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.
preprocessor. @xref{C++ Named Operators}.
In the 1999 C standard, identifiers may contain letters which are not
-part of the ``basic source character set,'' at the implementation's
+part of the ``basic source character set'', at the implementation's
discretion (such as accented Latin letters, Greek letters, or Chinese
ideograms). This may be done with an extended character set, or the
-@samp{\u} and @samp{\U} escape sequences. GCC does not presently
-implement either feature in the preprocessor or the compiler.
+@samp{\u} and @samp{\U} escape sequences. The implementation of this
+feature in GCC is experimental; such characters are only accepted in
+the @samp{\u} and @samp{\U} forms and only if
+@option{-fextended-identifiers} is used.
As an extension, GCC treats @samp{$} as a letter. This is for
compatibility with some systems, such as VMS, where @samp{$} is commonly
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
+Any other single character is considered ``other''. It is passed on to
the preprocessor's output unmolested. The C compiler will almost
certainly reject source code containing ``other'' tokens. In ASCII, the
only other characters are @samp{@@}, @samp{$}, @samp{`}, and control
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,
* Include Operation::
* Search Path::
* Once-Only Headers::
+* Alternatives to Wrapper #ifndef::
* Computed Includes::
* Wrapper Headers::
* System Headers::
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
@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"
@{
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);
@{
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
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
@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.
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, @option{-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{""}
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
#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,
file, the macro name should contain the name of the file and some
additional text, to avoid conflicts with other header files.
+@node Alternatives to Wrapper #ifndef
+@section Alternatives to Wrapper #ifndef
+
+CPP supports two more ways of indicating that a header file should be
+read only once. Neither one is as portable as a wrapper @samp{#ifndef}
+and we recommend you do not use them in new programs, with the caveat
+that @samp{#import} is standard practice in Objective-C.
+
+@findex #import
+CPP supports a variant of @samp{#include} called @samp{#import} which
+includes a file, but does so at most once. If you use @samp{#import}
+instead of @samp{#include}, then you don't need the conditionals
+inside the header file to prevent multiple inclusion of the contents.
+@samp{#import} is standard in Objective-C, but is considered a
+deprecated extension in C and C++.
+
+@samp{#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 users
+don't need to know this. Using a wrapper @samp{#ifndef} accomplishes
+this goal.
+
+In the present implementation, a single use of @samp{#import} will
+prevent the file from ever being read again, by either @samp{#import} or
+@samp{#include}. You should not rely on this; do not use both
+@samp{#import} and @samp{#include} to refer to the same header file.
+
+Another way to prevent a header file from being included more than once
+is with the @samp{#pragma once} directive. If @samp{#pragma once} is
+seen when scanning a header file, that file will never be read again, no
+matter what.
+
+@samp{#pragma once} does not have the problems that @samp{#import} does,
+but it is not recognized by all preprocessors, so you cannot rely on it
+in a portable program.
+
@node Computed Includes
@section Computed Includes
@cindex computed includes
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
#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
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
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.
There is no way to solve this problem within the C standard, but you can
use the GNU extension @samp{#include_next}. It means, ``Include the
-@emph{next} file with this name.'' This directive works like
+@emph{next} file with this name''. This directive works like
@samp{#include} except in searching for the specified file: it starts
searching the list of header file directories @emph{after} the directory
in which the current file was found.
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.
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
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
@expansion{} BUFSIZE
@expansion{} 1024
@end group
-@end example
+@end smallexample
@noindent
@code{TABLESIZE} is expanded first to produce @code{BUFSIZE}, then that
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}.
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 */
+#define foo() /* @r{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
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
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
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 +
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.)
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{} (( ) < ( ) ? ( ) : ( ))
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
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
Here is an example of a macro definition that uses stringification:
-@example
+@smallexample
@group
#define WARN_IF(EXP) \
do @{ if (EXP) \
@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
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
@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
needs to be a table of commands, perhaps an array of structures declared
as follows:
-@example
+@smallexample
@group
struct command
@{
@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
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[] =
COMMAND (help),
@dots{}
@};
-@end example
+@end smallexample
@node Variadic Macros
@section Variadic Macros
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
@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
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{@w{__VA_ARGS__}} and this
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
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
@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
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.
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
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.
+by a C compiler or an Objective-C compiler.
@item __ASSEMBLER__
This macro is defined with value 1 when preprocessing assembly
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 double
-underscores.
+which you are using GNU C or GNU Fortran. Their names all start with
+double underscores.
@table @code
+@item __COUNTER__
+This macro expands to sequential integral values starting from 0. In
+conjunction with the @code{##} operator, this provides a convenient means to
+generate unique identifiers. Care must be taken to ensure that
+@code{__COUNTER__} is not expanded prior to inclusion of precompiled headers
+which use it. Otherwise, the precompiled headers will not be used.
+
+@item __GFORTRAN__
+The GNU Fortran compiler defines this.
+
@item __GNUC__
@itemx __GNUC_MINOR__
@itemx __GNUC_PATCHLEVEL__
These macros are defined by all GNU compilers that use the C
-preprocessor: C, C++, and Objective-C@. Their values are the major
+preprocessor: C, C++, Objective-C and Fortran. Their values are the major
version, minor version, and patch level of the compiler, as integer
constants. For example, GCC 3.2.1 will define @code{__GNUC__} to 3,
-@code{__GNUC_MINOR__} to 2, and @code{__GNUC_PATCHLEVEL__} to 1. They
-are defined only when the entire compiler is in use; if you invoke the
-preprocessor directly, they are not defined.
+@code{__GNUC_MINOR__} to 2, and @code{__GNUC_PATCHLEVEL__} to 1. These
+macros are also defined if you invoke the preprocessor directly.
@code{__GNUC_PATCHLEVEL__} is new to GCC 3.0; it is also present in the
widely-used development snapshots leading up to 3.0 (which identify
themselves as GCC 2.96 or 2.97, depending on which snapshot you have).
If all you need to know is whether or not your program is being compiled
-by GCC, you can simply test @code{__GNUC__}. If you need to write code
+by GCC, or a non-GCC compiler that claims to accept the GNU C dialects,
+you can simply test @code{__GNUC__}. If you need to write code
which depends on a specific version, you must be more careful. Each
time the minor version is increased, the patch level is reset to zero;
each time the major version is increased (which happens rarely), 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.
This macro expands to a decimal integer constant that represents the
depth of nesting in include files. The value of this macro is
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
+end of every included file. It starts out at 0, its value within the
base file specified on the command line.
@item __ELF__
sure that programs will execute with the same effect whether or not they
are defined. If they are defined, their value is 1.
+@item __GNUC_GNU_INLINE__
+GCC defines this macro if functions declared @code{inline} will be
+handled in GCC's traditional gnu90 mode. Object files will contain
+externally visible definitions of all functions declared @code{inline}
+without @code{extern} or @code{static}. They will not contain any
+definitions of any functions declared @code{extern inline}.
+
+@item __GNUC_STDC_INLINE__
+GCC defines this macro if functions declared @code{inline} will be
+handled according to the ISO C99 standard. Object files will contain
+externally visible definitions of all functions declared @code{extern
+inline}. They will not contain definitions of any functions declared
+@code{inline} without @code{extern}.
+
+If this macro is defined, GCC supports the @code{gnu_inline} function
+attribute as a way to always get the gnu90 behavior. Support for
+this and @code{__GNUC_GNU_INLINE__} was added in GCC 4.1.3. If
+neither macro is defined, an older version of GCC is being used:
+@code{inline} functions will be compiled in gnu90 mode, and the
+@code{gnu_inline} function attribute will not be recognized.
+
@item __CHAR_UNSIGNED__
GCC defines this macro if and only if the data type @code{char} is
unsigned on the target machine. It exists to cause the standard header
@itemx __PTRDIFF_TYPE__
@itemx __WCHAR_TYPE__
@itemx __WINT_TYPE__
+@itemx __INTMAX_TYPE__
+@itemx __UINTMAX_TYPE__
+@itemx __SIG_ATOMIC_TYPE__
+@itemx __INT8_TYPE__
+@itemx __INT16_TYPE__
+@itemx __INT32_TYPE__
+@itemx __INT64_TYPE__
+@itemx __UINT8_TYPE__
+@itemx __UINT16_TYPE__
+@itemx __UINT32_TYPE__
+@itemx __UINT64_TYPE__
+@itemx __INT_LEAST8_TYPE__
+@itemx __INT_LEAST16_TYPE__
+@itemx __INT_LEAST32_TYPE__
+@itemx __INT_LEAST64_TYPE__
+@itemx __UINT_LEAST8_TYPE__
+@itemx __UINT_LEAST16_TYPE__
+@itemx __UINT_LEAST32_TYPE__
+@itemx __UINT_LEAST64_TYPE__
+@itemx __INT_FAST8_TYPE__
+@itemx __INT_FAST16_TYPE__
+@itemx __INT_FAST32_TYPE__
+@itemx __INT_FAST64_TYPE__
+@itemx __UINT_FAST8_TYPE__
+@itemx __UINT_FAST16_TYPE__
+@itemx __UINT_FAST32_TYPE__
+@itemx __UINT_FAST64_TYPE__
+@itemx __INTPTR_TYPE__
+@itemx __UINTPTR_TYPE__
These macros are defined to the correct underlying types for the
-@code{size_t}, @code{ptrdiff_t}, @code{wchar_t}, and @code{wint_t}
-typedefs, respectively. They exist to make the standard header files
-@file{stddef.h} and @file{wchar.h} work correctly. You should not use
-these macros directly; instead, include the appropriate headers and use
-the typedefs.
+@code{size_t}, @code{ptrdiff_t}, @code{wchar_t}, @code{wint_t},
+@code{intmax_t}, @code{uintmax_t}, @code{sig_atomic_t}, @code{int8_t},
+@code{int16_t}, @code{int32_t}, @code{int64_t}, @code{uint8_t},
+@code{uint16_t}, @code{uint32_t}, @code{uint64_t},
+@code{int_least8_t}, @code{int_least16_t}, @code{int_least32_t},
+@code{int_least64_t}, @code{uint_least8_t}, @code{uint_least16_t},
+@code{uint_least32_t}, @code{uint_least64_t}, @code{int_fast8_t},
+@code{int_fast16_t}, @code{int_fast32_t}, @code{int_fast64_t},
+@code{uint_fast8_t}, @code{uint_fast16_t}, @code{uint_fast32_t},
+@code{uint_fast64_t}, @code{intptr_t}, and @code{uintptr_t} typedefs,
+respectively. They exist to make the standard header files
+@file{stddef.h}, @file{stdint.h}, and @file{wchar.h} work correctly.
+You should not use these macros directly; instead, include the
+appropriate headers and use the typedefs. Some of these macros may
+not be defined on particular systems if GCC does not provide a
+@file{stdint.h} header on those systems.
@item __CHAR_BIT__
Defined to the number of bits used in the representation of the
@itemx __INT_MAX__
@itemx __LONG_MAX__
@itemx __LONG_LONG_MAX__
-Defined to the maximum value of the @code{signed char}, @code{wchar_t},
+@itemx __WINT_MAX__
+@itemx __SIZE_MAX__
+@itemx __PTRDIFF_MAX__
+@itemx __INTMAX_MAX__
+@itemx __UINTMAX_MAX__
+@itemx __SIG_ATOMIC_MAX__
+@itemx __INT8_MAX__
+@itemx __INT16_MAX__
+@itemx __INT32_MAX__
+@itemx __INT64_MAX__
+@itemx __UINT8_MAX__
+@itemx __UINT16_MAX__
+@itemx __UINT32_MAX__
+@itemx __UINT64_MAX__
+@itemx __INT_LEAST8_MAX__
+@itemx __INT_LEAST16_MAX__
+@itemx __INT_LEAST32_MAX__
+@itemx __INT_LEAST64_MAX__
+@itemx __UINT_LEAST8_MAX__
+@itemx __UINT_LEAST16_MAX__
+@itemx __UINT_LEAST32_MAX__
+@itemx __UINT_LEAST64_MAX__
+@itemx __INT_FAST8_MAX__
+@itemx __INT_FAST16_MAX__
+@itemx __INT_FAST32_MAX__
+@itemx __INT_FAST64_MAX__
+@itemx __UINT_FAST8_MAX__
+@itemx __UINT_FAST16_MAX__
+@itemx __UINT_FAST32_MAX__
+@itemx __UINT_FAST64_MAX__
+@itemx __INTPTR_MAX__
+@itemx __UINTPTR_MAX__
+@itemx __WCHAR_MIN__
+@itemx __WINT_MIN__
+@itemx __SIG_ATOMIC_MIN__
+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.
+@code{signed int}, @code{signed long}, @code{signed long long},
+@code{wint_t}, @code{size_t}, @code{ptrdiff_t},
+@code{intmax_t}, @code{uintmax_t}, @code{sig_atomic_t}, @code{int8_t},
+@code{int16_t}, @code{int32_t}, @code{int64_t}, @code{uint8_t},
+@code{uint16_t}, @code{uint32_t}, @code{uint64_t},
+@code{int_least8_t}, @code{int_least16_t}, @code{int_least32_t},
+@code{int_least64_t}, @code{uint_least8_t}, @code{uint_least16_t},
+@code{uint_least32_t}, @code{uint_least64_t}, @code{int_fast8_t},
+@code{int_fast16_t}, @code{int_fast32_t}, @code{int_fast64_t},
+@code{uint_fast8_t}, @code{uint_fast16_t}, @code{uint_fast32_t},
+@code{uint_fast64_t}, @code{intptr_t}, and @code{uintptr_t} types and
+to the minimum value of the @code{wchar_t}, @code{wint_t}, and
+@code{sig_atomic_t} 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.
+Some of these macros may not be defined on particular systems if GCC
+does not provide a @file{stdint.h} header on those systems.
+
+@item __INT8_C
+@itemx __INT16_C
+@itemx __INT32_C
+@itemx __INT64_C
+@itemx __UINT8_C
+@itemx __UINT16_C
+@itemx __UINT32_C
+@itemx __UINT64_C
+@itemx __INTMAX_C
+@itemx __UINTMAX_C
+Defined to implementations of the standard @file{stdint.h} macros with
+the same names without the leading @code{__}. They exist the make the
+implementation of that header work correctly. You should not use
+these macros directly; instead, include the appropriate headers. Some
+of these macros may not be defined on particular systems if GCC does
+not provide a @file{stdint.h} header on those systems.
+
+@item __SIZEOF_INT__
+@itemx __SIZEOF_LONG__
+@itemx __SIZEOF_LONG_LONG__
+@itemx __SIZEOF_SHORT__
+@itemx __SIZEOF_POINTER__
+@itemx __SIZEOF_FLOAT__
+@itemx __SIZEOF_DOUBLE__
+@itemx __SIZEOF_LONG_DOUBLE__
+@itemx __SIZEOF_SIZE_T__
+@itemx __SIZEOF_WCHAR_T__
+@itemx __SIZEOF_WINT_T__
+@itemx __SIZEOF_PTRDIFF_T__
+Defined to the number of bytes of the C standard data types: @code{int},
+@code{long}, @code{long long}, @code{short}, @code{void *}, @code{float},
+@code{double}, @code{long double}, @code{size_t}, @code{wchar_t}, @code{wint_t}
+and @code{ptrdiff_t}.
+
+@item __BYTE_ORDER__
+@itemx __ORDER_LITTLE_ENDIAN__
+@itemx __ORDER_BIG_ENDIAN__
+@itemx __ORDER_PDP_ENDIAN__
+@code{__BYTE_ORDER__} is defined to one of the values
+@code{__ORDER_LITTLE_ENDIAN__}, @code{__ORDER_BIG_ENDIAN__}, or
+@code{__ORDER_PDP_ENDIAN__} to reflect the layout of multi-byte and
+multi-word quantities in memory. If @code{__BYTE_ORDER__} is equal to
+@code{__ORDER_LITTLE_ENDIAN__} or @code{__ORDER_BIG_ENDIAN__}, then
+multi-byte and multi-word quantities are laid out identically: the
+byte (word) at the lowest address is the least significant or most
+significant byte (word) of the quantity, respectively. If
+@code{__BYTE_ORDER__} is equal to @code{__ORDER_PDP_ENDIAN__}, then
+bytes in 16-bit words are laid out in a little-endian fashion, whereas
+the 16-bit subwords of a 32-bit quantity are laid out in big-endian
+fashion.
+
+You should use these macros for testing like this:
+
+@smallexample
+/* @r{Test for a little-endian machine} */
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+@end smallexample
+
+@item __FLOAT_WORD_ORDER__
+@code{__FLOAT_WORD_ORDER__} is defined to one of the values
+@code{__ORDER_LITTLE_ENDIAN__} or @code{__ORDER_BIG_ENDIAN__} to reflect
+the layout of the words of multi-word floating-point quantities.
+
+@item __DEPRECATED
+This macro is defined, with value 1, when compiling a C++ source file
+with warnings about deprecated constructs enabled. These warnings are
+enabled by default, but can be disabled with @option{-Wno-deprecated}.
+
+@item __EXCEPTIONS
+This macro is defined, with value 1, when compiling a C++ source file
+with exceptions enabled. If @option{-fno-exceptions} is used when
+compiling the file, then this macro is not defined.
+
+@item __GXX_RTTI
+This macro is defined, with value 1, when compiling a C++ source file
+with runtime type identification enabled. If @option{-fno-rtti} is
+used when compiling the file, then this macro is not defined.
@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 __GXX_EXPERIMENTAL_CXX0X__
+This macro is defined when compiling a C++ source file with the option
+@option{-std=c++0x} or @option{-std=gnu++0x}. It indicates that some
+features likely to be included in C++0x are available. Note that these
+features are experimental, and may change or be removed in future
+versions of GCC.
+
+@item __GXX_WEAK__
+This macro is defined when compiling a C++ source file. It has the
+value 1 if the compiler will use weak symbols, COMDAT sections, or
+other similar techniques to collapse symbols with ``vague linkage''
+that are defined in multiple translation units. If the compiler will
+not collapse such symbols, this macro is defined with value 0. In
+general, user code should not need to make use of this macro; the
+purpose of this macro is to ease implementation of the C++ runtime
+library provided with G++.
+
@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
+(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__
-@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.
+
+@item __SSP__
+This macro is defined, with value 1, when @option{-fstack-protector} is in
+use.
+
+@item __SSP_ALL__
+This macro is defined, with value 2, when @option{-fstack-protector-all} is
+in use.
+
+@item __TIMESTAMP__
+This macro expands to a string constant that describes the date and time
+of the last modification of the current source file. The string constant
+contains abbreviated day of the week, month, day of the month, time in
+hh:mm:ss form, year and looks like @code{@w{"Sun Sep 16 01:03:52 1973"}}.
+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{__TIMESTAMP__} will expand to
+@code{@w{"??? ??? ?? ??:??:?? ????"}}.
+
+@item __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
+@itemx __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
+@itemx __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
+@itemx __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
+@itemx __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16
+These macros are defined when the target processor supports atomic compare
+and swap operations on operands 1, 2, 4, 8 or 16 bytes in length, respectively.
+
+@item __GCC_HAVE_DWARF2_CFI_ASM
+This macro is defined when the compiler is emitting Dwarf2 CFI directives
+to the assembler. When this is defined, it is possible to emit those same
+directives in inline assembly.
+
+@item __FP_FAST_FMA
+@itemx __FP_FAST_FMAF
+@itemx __FP_FAST_FMAL
+These macros are defined with value 1 if the backend supports the
+@code{fma}, @code{fmaf}, and @code{fmal} builtin functions, so that
+the include file @file{math.h} can define the macros
+@code{FP_FAST_FMA}, @code{FP_FAST_FMAF}, and @code{FP_FAST_FMAL}
+for compatibility with the 1999 C standard.
@end table
@node System-specific Predefined Macros
@subsection C++ Named Operators
@cindex named operators
@cindex C++ named operators
-@cindex iso646.h
+@cindex @file{iso646.h}
In C++, there are eleven keywords which are simply alternate spellings
of operators normally written with punctuation. These keywords are
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
@noindent
These definitions are effectively the same:
-@example
+@smallexample
#define FOUR (2 + 2)
#define FOUR (2 + 2)
-#define FOUR (2 /* two */ + 2)
-@end example
+#define FOUR (2 /* @r{two} */ + 2)
+@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
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
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.
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
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
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
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
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
@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)}
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.
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{}
next = min (x + y, tem);
@}
@end group
-@end example
+@end smallexample
@noindent
(where we assume that @code{foo} returns type @code{int}).
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.
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
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))
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
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
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)}
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.
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
The simplest sort of conditional is
-@example
+@smallexample
@group
#ifdef @var{MACRO}
#endif /* @var{MACRO} */
@end group
-@end example
+@end smallexample
@cindex conditional group
This block is called a @dfn{conditional group}. @var{controlled text}
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}
#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
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
@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
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}},
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}
@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
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 */
@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
#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
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
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
preprocessor itself. Other pragmas are meaningful to the C or C++
compilers. They are documented in the GCC manual.
+GCC plugins may provide their own pragmas.
+
@ftable @code
@item #pragma GCC dependency
@code{#pragma GCC dependency} allows you to check the relative dates of
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
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.
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.
@chapter Other Directives
@findex #ident
+@findex #sccs
The @samp{#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.
+the object file. On other systems, the directive is ignored. The
+@samp{#sccs} directive is a synonym for @samp{#ident}.
-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, 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.
+These directives are not part of the C standard, but they are not
+official GNU extensions either. What historical information we have
+been able to find, suggests they originated with System V@.
@cindex null directive
The @dfn{null directive} consists of a @samp{#} followed by a newline,
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
@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. */
+/* @r{This is a comment. The following #include directive
+ is ill-formed.} */
#include <stdio.h
@end smallexample
whitespace.
One consequence is that it is legitimate for the replacement text to
-contain an unmatched quote (@pxref{Traditional lexical analysis}). An
+contain an unmatched quote (@pxref{Traditional lexical analysis}). An
unclosed string or character constant continues into the text
following the macro call. Similarly, the text at the end of a macro's
expansion can run together with the text after the macro invocation to
@smallexample
#define str(x) "x"
-str(/* A comment */some text )
+str(/* @r{A comment} */some text )
@expansion{} "some text "
@end smallexample
@item The mapping of physical source file multi-byte characters to the
execution character set.
-Currently, CPP requires its input to be ASCII or UTF-8. The execution
-character set may be controlled by the user, with the
-@code{-ftarget-charset} and @code{-ftarget-wide-charset} options.
+The input character set can be specified using the
+@option{-finput-charset} option, while the execution character set may
+be controlled using the @option{-fexec-charset} and
+@option{-fwide-exec-charset} options.
@item Identifier characters.
@anchor{Identifier characters}
The C and C++ standards allow identifiers to be composed of @samp{_}
and the alphanumeric characters. C++ and C99 also allow universal
-character names (not implemented in GCC), and C99 further permits
-implementation-defined characters.
+character names, and C99 further permits implementation-defined
+characters. GCC currently only permits universal character names if
+@option{-fextended-identifiers} is used, because the implementation of
+universal character names in identifiers is experimental.
GCC allows the @samp{$} character in identifiers as an extension for
most targets. This is true regardless of the @option{std=} switch,
identifier characters by default.
Currently the targets that by default do not permit @samp{$} are AVR,
-IP2K, MMIX, MIPS Irix 3, ARM aout, and PowerPC targets for the AIX and
-BeOS operating systems.
+IP2K, MMIX, MIPS Irix 3, ARM aout, and PowerPC targets for the AIX
+operating system.
You can override the default with @option{-fdollars-in-identifiers} or
@option{fno-dollars-in-identifiers}. @xref{fdollars-in-identifiers}.
same way; i.e.@: escape sequences such as @samp{\a} are given the
values they would have on the target machine.
-The compiler values a multi-character character constant a character
+The compiler evaluates a multi-character character constant a character
at a time, shifting the previous value left by the number of bits per
target character, and then or-ing in the bit-pattern of the new
character truncated to the width of a target character. The final
bit-pattern is given type @code{int}, and is therefore signed,
regardless of whether single characters are signed or not (a slight
-change from versions 3.1 and earlier of GCC). If there are more
+change from versions 3.1 and earlier of GCC)@. If there are more
characters in the constant than would fit in the target @code{int} the
compiler issues a warning, and the excess leading characters are
ignored.
-For example, 'ab' for a target with an 8-bit @code{char} would be
-interpreted as @w{(int) ((unsigned char) 'a' * 256 + (unsigned char)
-'b')}, and '\234a' as @w{(int) ((unsigned char) '\234' * 256 + (unsigned
-char) 'a')}.
+For example, @code{'ab'} for a target with an 8-bit @code{char} would be
+interpreted as @w{@samp{(int) ((unsigned char) 'a' * 256 + (unsigned char)
+'b')}}, and @code{'\234a'} as @w{@samp{(int) ((unsigned char) '\234' *
+256 + (unsigned char) 'a')}}.
@item Source file inclusion.
CPP has a small number of internal limits. This section lists the
limits which the C standard requires to be no lower than some minimum,
-and all the others we are aware of. We intend there to be as few limits
+and all the others known. It is intended that there should be as few limits
as possible. If you encounter an undocumented or inconvenient limit,
-please report that to us as a bug. (See the section on reporting bugs in
-the GCC manual.)
+please report that as a bug. @xref{Bugs, , Reporting Bugs, gcc, Using
+the GNU Compiler Collection (GCC)}.
Where we say something is limited @dfn{only by available memory}, that
means that internal data structures impose no intrinsic limit, and space
@node Obsolete Features
@section Obsolete Features
-CPP has a number of features which are present mainly for
-compatibility with older programs. We discourage their use in new code.
-In some cases, we plan to remove the feature in a future version of GCC@.
-
-@menu
-* Assertions::
-* Obsolete once-only headers::
-@end menu
+CPP has some features which are present mainly for compatibility with
+older programs. We discourage their use in new code. In some cases,
+we plan to remove the feature in a future version of GCC@.
-@node Assertions
@subsection Assertions
@cindex assertions
define them with preprocessing directives or command-line options.
Assertions were intended to provide a more systematic way to describe
-the compiler's target system. However, in practice they are just as
-unpredictable as the system-specific predefined macros. In addition, they
-are not part of any standard, and only a few compilers support them.
+the compiler's target system and we added them for compatibility with
+existing compilers. In practice they are just as unpredictable as the
+system-specific predefined macros. In addition, they are not part of
+any standard, and only a few compilers support them.
Therefore, the use of assertions is @strong{less} portable than the use
of system-specific predefined macros. We recommend you do not use them at
all.
@cindex predicates
An assertion looks like this:
-@example
+@smallexample
#@var{predicate} (@var{answer})
-@end example
+@end smallexample
@noindent
@var{predicate} must be a single identifier. @var{answer} can be any
conditional succeeds if either @code{vax} or @code{ns16000} has been
asserted as an answer for @code{machine}.
-@example
+@smallexample
#if #machine (vax) || #machine (ns16000)
-@end example
+@end smallexample
@noindent
You can test whether @emph{any} answer is asserted for a predicate by
omitting the answer in the conditional:
-@example
+@smallexample
#if #machine
-@end example
+@end smallexample
@findex #assert
Assertions are made with the @samp{#assert} directive. Its sole
argument is the assertion to make, without the leading @samp{#} that
identifies assertions in conditionals.
-@example
+@smallexample
#assert @var{predicate} (@var{answer})
-@end example
+@end smallexample
@noindent
You may make several assertions with the same predicate and different
for that predicate remain true. You can cancel an entire predicate by
leaving out the answer:
-@example
+@smallexample
#unassert @var{predicate}
-@end example
+@end smallexample
@noindent
In either form, if no such assertion has been made, @samp{#unassert} has
You can also make or cancel assertions using command line options.
@xref{Invocation}.
-@node Obsolete once-only headers
-@subsection Obsolete once-only headers
-
-CPP supports two more ways of indicating that a header file should be
-read only once. Neither one is as portable as a wrapper @samp{#ifndef},
-and we recommend you do not use them in new programs.
-
-@findex #import
-In the Objective-C language, there is a variant of @samp{#include}
-called @samp{#import} which includes a file, but does so at most once.
-If you use @samp{#import} instead of @samp{#include}, then you don't
-need the conditionals inside the header file to prevent multiple
-inclusion of the contents. GCC permits the use of @samp{#import} in C
-and C++ as well as Objective-C@. However, it is not in standard C or C++
-and should therefore not be used by portable programs.
-
-@samp{#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 users
-don't need to know this. Using a wrapper @samp{#ifndef} accomplishes
-this goal.
-
-In the present implementation, a single use of @samp{#import} will
-prevent the file from ever being read again, by either @samp{#import} or
-@samp{#include}. You should not rely on this; do not use both
-@samp{#import} and @samp{#include} to refer to the same header file.
-
-Another way to prevent a header file from being included more than once
-is with the @samp{#pragma once} directive. If @samp{#pragma once} is
-seen when scanning a header file, that file will never be read again, no
-matter what.
-
-@samp{#pragma once} does not have the problems that @samp{#import} does,
-but it is not recognized by all preprocessors, so you cannot rely on it
-in a portable program.
-
@node Differences from previous versions
@section Differences from previous versions
@cindex differences from previous versions
@itemize @bullet
+@item -I- deprecated
+
+This option has been deprecated in 4.0. @option{-iquote} is meant to
+replace the need for this option.
+
@item Order of evaluation of @samp{#} and @samp{##} operators
The standard does not specify the order of evaluation of a chain of
@item @samp{#line} and @samp{#include}
The @samp{#line} directive used to change GCC's notion of the
-``directory containing the current file,'' used by @samp{#include} with
+``directory containing the current file'', used by @samp{#include} with
a double-quoted header file name. In 3.0 and later, it does not.
@xref{Line Control}, for further explanation.
except that the C compiler has different rules for specifying the output
file.
-@strong{Note:} Whether you use the preprocessor by way of @command{gcc}
+@emph{Note:} Whether you use the preprocessor by way of @command{gcc}
or @command{cpp}, the @dfn{compiler driver} is run first. This
program's purpose is to translate your command into invocations of the
programs that do the actual work. Their command line interfaces are
@ignore
@c man begin SYNOPSIS
cpp [@option{-D}@var{macro}[=@var{defn}]@dots{}] [@option{-U}@var{macro}]
- [@option{-I}@var{dir}@dots{}] [@option{-W}@var{warn}@dots{}]
+ [@option{-I}@var{dir}@dots{}] [@option{-iquote}@var{dir}@dots{}]
+ [@option{-W}@var{warn}@dots{}]
[@option{-M}|@option{-MM}] [@option{-MG}] [@option{-MF} @var{filename}]
- [@option{-MP}] [@option{-MQ} @var{target}@dots{}] [@option{-MT} @var{target}@dots{}]
+ [@option{-MP}] [@option{-MQ} @var{target}@dots{}]
+ [@option{-MT} @var{target}@dots{}]
+ [@option{-P}] [@option{-fno-working-directory}]
[@option{-x} @var{language}] [@option{-std=}@var{standard}]
@var{infile} @var{outfile}
@option{-M} (@pxref{Invocation}). These take precedence over
environment variables, which in turn take precedence over the
configuration of GCC@.
-
+
@include cppenv.texi
@c man end