summaryrefslogtreecommitdiffstats
path: root/contrib/gcc/doc/cpp.texi
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/gcc/doc/cpp.texi')
-rw-r--r--contrib/gcc/doc/cpp.texi588
1 files changed, 380 insertions, 208 deletions
diff --git a/contrib/gcc/doc/cpp.texi b/contrib/gcc/doc/cpp.texi
index 39e6a28..a6d6fb0 100644
--- a/contrib/gcc/doc/cpp.texi
+++ b/contrib/gcc/doc/cpp.texi
@@ -6,10 +6,10 @@
@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
Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
@@ -23,9 +23,7 @@ section entitled ``GNU Free Documentation License''.
man page gfdl(7).
@c man end
@end ignore
-@end macro
-@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).
@@ -40,7 +38,7 @@ This manual contains no Invariant Sections. The Front-Cover Texts are
software. Copies published by the Free Software Foundation raise
funds for GNU development.
@c man end
-@end macro
+@end copying
@macro gcctabopt{body}
@code{\body\}
@@ -48,6 +46,7 @@ This manual contains no Invariant Sections. The Front-Cover Texts are
@c Create a separate index for command line options.
@defcodeindex op
+@syncodeindex vr op
@c Used in cppopts.texi and cppenv.texi.
@set cppmanual
@@ -69,12 +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
+@ifnottex
@node Top
@top
The C preprocessor implements the macro language used to transform C,
@@ -96,8 +95,8 @@ useful on its own.
* Invocation::
* Environment Variables::
* GNU Free Documentation License::
-* Option Index::
* Index of Directives::
+* Option Index::
* Concept Index::
@detailmenu
@@ -129,6 +128,7 @@ Macros
* Variadic Macros::
* Predefined Macros::
* Undefining and Redefining Macros::
+* Directives Within Macro Arguments::
* Macro Pitfalls::
Predefined Macros
@@ -173,14 +173,11 @@ Obsolete Features
* Assertions::
* Obsolete once-only headers::
-* Miscellaneous obsolete features::
@end detailmenu
@end menu
-@ifnottex
-@copyrightnotice{}
-@covertexts{}
+@insertcopying
@end ifnottex
@node Overview
@@ -203,7 +200,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.
@@ -223,6 +220,16 @@ 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
@@ -237,7 +244,7 @@ diagnostics, you must also use @option{-pedantic}. @xref{Invocation}.
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.
@@ -248,7 +255,7 @@ standard.
@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
+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
@@ -274,16 +281,17 @@ 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
@@ -401,26 +409,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
@@ -535,11 +525,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
@@ -795,10 +784,10 @@ 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
@@ -909,7 +898,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.
@@ -1128,6 +1117,7 @@ macros when you are compiling C++.
* Variadic Macros::
* Predefined Macros::
* Undefining and Redefining Macros::
+* Directives Within Macro Arguments::
* Macro Pitfalls::
@end menu
@@ -1621,7 +1611,7 @@ 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
@@ -1631,7 +1621,7 @@ The @code{eprintf} macro above could be written
@end example
@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
@@ -1705,7 +1695,7 @@ 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
@@ -1800,23 +1790,31 @@ 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
@@ -1835,8 +1833,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
@@ -1970,6 +1968,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
@@ -2000,10 +2002,35 @@ 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.
@end table
@node System-specific Predefined Macros
@@ -2136,6 +2163,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
@@ -2723,7 +2794,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
@@ -3059,7 +3130,7 @@ file it specifies, until something else happens to change that.
constant: backslash escapes are interpreted. This is different from
@samp{#include}.
-Previous versions of GNU CPP did not interpret escapes in @samp{#line};
+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.
@@ -3226,8 +3297,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.
@@ -3321,91 +3392,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 <stdio.h
+@end smallexample
+
+Just as for the ISO preprocessor, what would be a closing quote can be
+escaped with a backslash to prevent the quoted text from closing.
+
+@node Traditional macros
+@section Traditional macros
+
+The major difference between traditional and ISO macros is that the
+former expand to text rather than to a token sequence. CPP removes
+all leading and trailing horizontal whitespace from a macro's
+replacement text before storing it, but preserves the form of internal
+whitespace.
+
+One consequence is that it is legitimate for the replacement text to
+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
+produce a single token.
+
+Normally comments are removed from the replacement text after the
+macro is expanded, but if the @option{-CC} option is passed on the
+command line comments are preserved. (In fact, the current
+implementation removes comments even before saving the macro
+replacement text, but it careful to do it in such a way that the
+observed effect is identical even in the function-like macro case.)
+
+The ISO stringification operator @samp{#} and token paste operator
+@samp{##} have no special meaning. As explained later, an effect
+similar to these operators can be obtained in a different way. Macro
+names that are embedded in quotes, either from the main file or after
+macro replacement, do not expand.
+
+CPP replaces an unquoted object-like macro name with its replacement
+text, and then rescans it for further macros to replace. Unlike
+standard macro expansion, traditional macro expansion has no provision
+to prevent recursion. If an object-like macro appears unquoted in its
+replacement text, it will be replaced again during the rescan pass,
+and so on @emph{ad infinitum}. GCC detects when it is expanding
+recursive macros, emits an error message, and continues after the
+offending macro invocation.
+
+@smallexample
+#define PLUS +
+#define INC(x) PLUS+x
+INC(foo);
+ @expansion{} ++foo;
+@end smallexample
+
+Function-like macros are similar in form but quite different in
+behavior to their ISO counterparts. Their arguments are contained
+within parentheses, are comma-separated, and can cross physical lines.
+Commas within nested parentheses are not treated as argument
+separators. Similarly, a quote in an argument cannot be left
+unclosed; a following comma or parenthesis that comes before the
+closing quote is treated like any other character. There is no
+facility for handling variadic macros.
+
+This implementation removes all comments from macro arguments, unless
+the @option{-C} option is given. The form of all other horizontal
+whitespace in arguments is preserved, including leading and trailing
+whitespace. In particular
+
+@smallexample
+f( )
+@end smallexample
+
+@noindent
+is treated as an invocation of the macro @samp{f} with a single
+argument consisting of a single space. If you want to invoke a
+function-like macro that takes no arguments, you must not leave any
+whitespace between the parentheses.
+
+If a macro argument crosses a new line, the new line is replaced with
+a space when forming the argument. If the previous line contained an
+unterminated quote, the following line inherits the quoted state.
+
+Traditional preprocessors replace parameters in the replacement text
+with their arguments regardless of whether the parameters are within
+quotes or not. This provides a way to stringize arguments. For
+example
+
+@smallexample
+#define str(x) "x"
+str(/* A comment */some text )
+ @expansion{} "some text "
+@end smallexample
+
+@noindent
+Note that the comment is removed, but that the trailing space is
+preserved. Here is an example of using a comment to effect token
+pasting.
+
+@smallexample
+#define suffix(x) foo_/**/x
+suffix(bar)
+ @expansion{} foo_bar
+@end smallexample
+
+@node Traditional miscellany
+@section Traditional miscellany
+
+Here are some things to be aware of when using the traditional
+preprocessor.
+
+@itemize @bullet
@item
-In traditional C, the text at the end of a macro expansion can run
-together with the text after the macro call, to produce a single token.
-This is impossible in ISO C@.
+Preprocessing directives are recognized only when their leading
+@samp{#} appears in the first column. There can be no whitespace
+between the beginning of the line and the @samp{#}, but whitespace can
+follow the @samp{#}.
@item
-None of the GNU extensions to the preprocessor are available in
-traditional mode, with the exception of a partial implementation of
-assertions, and those may be removed in the future.
+A true traditional C preprocessor does not recognize @samp{#error} or
+@samp{#pragma}, and may not recognize @samp{#elif}. CPP supports all
+the directives in traditional mode that it supports in ISO mode,
+including extensions, with the exception that the effects of
+@samp{#pragma GCC poison} are undefined.
@item
-A true traditional C preprocessor does not recognize @samp{#elif},
-@samp{#error}, or @samp{#pragma}. GCC supports @samp{#elif} and
-@samp{#error} even in traditional mode, but not @samp{#pragma}.
+__STDC__ is not defined.
@item
-Traditional mode is text-based, not token-based, and comments are
-stripped after macro expansion. Therefore, @samp{/**/} can be used to
-paste tokens together provided that there is no whitespace between it
-and the tokens to be pasted.
+If you use digraphs the behavior is undefined.
@item
-Traditional mode preserves the amount and form of whitespace provided by
-the user. Hard tabs remain hard tabs. This can be useful, e.g.@: if you
-are preprocessing a Makefile (which we do not encourage).
+If a line that looks like a directive appears within macro arguments,
+the behavior is undefined.
+
@end itemize
+@node Traditional warnings
+@section Traditional warnings
You can request warnings about features that did not exist, or worked
differently, in traditional C with the @option{-Wtraditional} option.
-This works only if you do @emph{not} specify @option{-traditional}. GCC
-does not warn about features of ISO C which you must use when you are
-using a conforming compiler, such as the @samp{#} and @samp{##}
+GCC does not warn about features of ISO C which you must use when you
+are using a conforming compiler, such as the @samp{#} and @samp{##}
operators.
Presently @option{-Wtraditional} warns about:
@@ -3428,9 +3638,9 @@ traditional implementations would not recognize @samp{#elif}, so it
suggests avoiding it altogether.
@item
-A function-like macro that appears without an argument list. In
-traditional C this was an error. In ISO C it merely means that the
-macro is not expanded.
+A function-like macro that appears without an argument list. In some
+traditional preprocessors this was an error. In ISO C it merely means
+that the macro is not expanded.
@item
The unary plus operator. This did not exist in traditional C@.
@@ -3458,7 +3668,7 @@ reliance on behavior described here, as it is possible that it will
change subtly in future implementations.
Also documented here are obsolete features and changes from previous
-versions of GNU CPP@.
+versions of CPP@.
@menu
* Implementation-defined behavior::
@@ -3471,7 +3681,7 @@ versions of GNU CPP@.
@section Implementation-defined behavior
@cindex implementation-defined behavior
-This is how GNU CPP behaves in all the cases which the C standard
+This is how CPP behaves in all the cases which the C standard
describes as @dfn{implementation-defined}. This term means that the
implementation is free to do what it likes, but must document its choice
and stick to it.
@@ -3494,17 +3704,25 @@ same column as it did in the original source file.
@item The numeric value of character constants in preprocessor expressions.
-The preprocessor and compiler interpret character constants in the same
-way; escape sequences such as @samp{\a} are given the values they would
-have on the target machine.
-
-Multi-character character constants are interpreted a character at a
-time, shifting the previous result left by the number of bits per
-character on the host, and adding the new character. For example, 'ab'
-on an 8-bit host would be interpreted as @w{'a' * 256 + 'b'}. If there
-are more characters in the constant than can fit in the widest native
-integer type on the host, usually a @code{long}, the excess characters
-are ignored and a diagnostic is given.
+The preprocessor and compiler interpret character constants in the
+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
+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
+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')}.
@item Source file inclusion.
@@ -3531,7 +3749,7 @@ pragmas.
@section Implementation limits
@cindex implementation limits
-GNU CPP has a small number of internal limits. This section lists the
+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
as possible. If you encounter an undocumented or inconvenient limit,
@@ -3554,10 +3772,10 @@ The standard requires at least 15 levels.
@item Nesting levels of conditional inclusion.
-The C standard mandates this be at least 63. GNU CPP is limited only by
+The C standard mandates this be at least 63. CPP is limited only by
available memory.
-@item Levels of parenthesised expressions within a full expression.
+@item Levels of parenthesized expressions within a full expression.
The C standard requires this to be at least 63. In preprocessor
conditional expressions, it is limited only by available memory.
@@ -3569,7 +3787,7 @@ requires only that the first 63 be significant.
@item Number of macros simultaneously defined in a single translation unit.
-The standard requires at least 4095 be possible. GNU CPP is limited only
+The standard requires at least 4095 be possible. CPP is limited only
by available memory.
@item Number of parameters in a macro definition and arguments in a macro call.
@@ -3579,7 +3797,7 @@ required by the standard is 127.
@item Number of characters on a logical source line.
-The C standard requires a minimum of 4096 be permitted. GNU CPP places
+The C standard requires a minimum of 4096 be permitted. CPP places
no limits on this, but you may get incorrect column numbers reported in
diagnostics for lines longer than 65,535 characters.
@@ -3596,14 +3814,13 @@ may not be a limitation.
@node Obsolete Features
@section Obsolete Features
-GNU CPP has a number of features which are present mainly for
+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::
-* Miscellaneous obsolete features::
@end menu
@node Assertions
@@ -3671,9 +3888,9 @@ answers. Subsequent assertions do not override previous ones for the
same predicate. All the answers for any given predicate are
simultaneously true.
-@cindex assertions, cancelling
+@cindex assertions, canceling
@findex #unassert
-Assertions can be cancelled with the @samp{#unassert} directive. It
+Assertions can be canceled with the @samp{#unassert} directive. It
has the same syntax as @samp{#assert}. In that form it cancels only the
answer which was specified on the @samp{#unassert} line; other answers
for that predicate remain true. You can cancel an entire predicate by
@@ -3693,7 +3910,7 @@ You can also make or cancel assertions using command line options.
@node Obsolete once-only headers
@subsection Obsolete once-only headers
-GNU CPP supports two more ways of indicating that a header file should be
+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.
@@ -3726,49 +3943,12 @@ matter what.
but it is not recognized by all preprocessors, so you cannot rely on it
in a portable program.
-@node Miscellaneous obsolete features
-@subsection Miscellaneous obsolete features
-
-Here are a few more obsolete features.
-
-@itemize @bullet
-@cindex invalid token paste
-@item Attempting to paste two tokens which together do not form a valid
-preprocessing token.
-
-The preprocessor currently warns about this, and the resulting
-preprocessed output is undefined. The tokens remain distinct if the
-preprocessor is being used directly by the compiler front end.
-
-Most of the time, when you get this warning, you will find that @samp{##}
-is being used superstitiously, to guard against whitespace appearing
-between two tokens. It is almost always safe to delete the @samp{##}.
-
-@cindex pragma poison
-@item @code{#pragma poison}
-
-This is the same as @code{#pragma GCC poison}. The version without the
-@code{GCC} prefix is deprecated. @xref{Pragmas}.
-
-@cindex multi-line string constants
-@item Multi-line string constants
-
-GCC currently allows a string constant to extend across multiple logical
-lines of the source file. This extension is deprecated and will be
-removed in a future version of GCC@. Such string constants are already
-rejected in all directives apart from @samp{#define}.
-
-Instead, make use of ISO C concatenation of adjacent string literals, or
-use @samp{\n} followed by a backslash-newline.
-
-@end itemize
-
@node Differences from previous versions
@section Differences from previous versions
@cindex differences from previous versions
This section details behavior which has changed from previous versions
-of GNU CPP@. We do not plan to change it again in the near future, but
+of CPP@. We do not plan to change it again in the near future, but
we do not promise not to, either.
The ``previous versions'' discussed here are 2.95 and before. The
@@ -3794,7 +3974,7 @@ GCC 3.0 evaluates @samp{#} and @samp{##} at the same time and strictly
left to right. Older versions evaluated all @samp{#} operators first,
then all @samp{##} operators, in an unreliable order.
-@item The form of whitespace betwen tokens in preprocessor output
+@item The form of whitespace between tokens in preprocessor output
@xref{Preprocessor Output}, for the current textual format. This is
also the format used by stringification. Normally, the preprocessor
@@ -3817,7 +3997,7 @@ versions accepted it silently.
Formerly, in a macro expansion, if @samp{##} appeared before a variable
arguments parameter, and the set of tokens specified for that argument
-in the macro invocation was empty, previous versions of GNU CPP would
+in the macro invocation was empty, previous versions of CPP would
back up and remove the preceding sequence of non-whitespace characters
(@strong{not} the preceding token). This extension is in direct
conflict with the 1999 C standard and has been drastically pared back.
@@ -3828,15 +4008,6 @@ omitted entirely, the comma will be removed from the expansion. If the
variable argument is empty, or the token before @samp{##} is not a
comma, then @samp{##} behaves as a normal token paste.
-@item Traditional mode and GNU extensions
-
-Traditional mode used to be implemented in the same program as normal
-preprocessing. Therefore, all the GNU extensions to the preprocessor
-were still available in traditional mode. It is now a separate program
-and does not implement any of the GNU extensions, except for a partial
-implementation of assertions. Even those may be removed in a future
-release.
-
@item @samp{#line} and @samp{#include}
The @samp{#line} directive used to change GCC's notion of the
@@ -3934,25 +4105,26 @@ Note that you can also specify places to search using options such as
@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
+@page
@include fdl.texi
@page
-@node Option Index
-@unnumbered Option Index
-
-CPP's command line options are indexed here without any initial
-@samp{-} or @samp{--}.
-
-@printindex op
-
@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
OpenPOWER on IntegriCloud