The C Preprocessor
10. Traditional Mode
Traditional (pre-standard) C preprocessing is rather different from
the preprocessing specified by the standard. When GCC is given the
`-traditional' option, it attempts to emulate a traditional
preprocessor. We do not guarantee that GCC's behavior under
`-traditional' matches any pre-standard preprocessor exactly.
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.
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.
-
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.
-
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.
-
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.)
-
Preprocessing directives are recognized in traditional C only when their
leading `#' appears in the first column. There can be no
whitespace between the beginning of the line and the `#'.
-
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 `##' is used in ISO C, to paste macro arguments together.
-
Traditional C does not have the concept of a preprocessing number.
-
A macro is not suppressed within its own definition, in traditional C.
Thus, any macro that is used recursively inevitably causes an error.
-
The `#' and `##' operators are not available in traditional
C.
-
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.
-
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 `#elif',
`#error', or `#pragma'. GCC supports `#elif' and
`#error' even in traditional mode, but not `#pragma'.
-
Traditional mode is text-based, not token-based, and comments are
stripped after macro expansion. Therefore, `/**/' can be used to
paste tokens together provided that there is no whitespace between it
and the tokens to be pasted.
-
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).
You can request warnings about features that did not exist, or worked
differently, in traditional C with the `-Wtraditional' option.
This works only if you do not specify `-traditional'. GCC
does not warn about features of ISO C which you must use when you are
using a conforming compiler, such as the `#' and `##'
operators.
Presently `-Wtraditional' warns about:
-
Macro parameters that appear within string literals in the macro body.
In traditional C macro replacement takes place within string literals,
but does not in ISO C.
-
In traditional C, some preprocessor directives did not exist.
Traditional preprocessors would only consider a line to be a directive
if the `#' appeared in column 1 on the line. Therefore
`-Wtraditional' warns about directives that traditional C
understands but would ignore because the `#' does not appear as the
first character on the line. It also suggests you hide directives like
`#pragma' not understood by traditional C by indenting them. Some
traditional implementations would not recognize `#elif', so it
suggests avoiding it altogether.
-
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.
-
The unary plus operator. This did not exist in traditional C.
-
The `U' and `LL' integer constant suffixes, which were not
available in traditional C. (Traditional C does support the `L'
suffix for simple long integer constants.) You are not warned about
uses of these suffixes in macros defined in system headers. For
instance,
UINT_MAX may well be defined as 4294967295U, but
you will not be warned if you use UINT_MAX.
You can usually avoid the warning, and the related warning about
constants which are so large that they are unsigned, by writing the
integer constant in question in hexadecimal, with no U suffix. Take
care, though, because this gives the wrong result in exotic cases.