From b6fb43ab3e59a0a4d9063daed96812eeb5a9fb47 Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Tue, 2 Jul 2002 22:20:33 +0000 Subject: [PATCH] cpp.texi: Update for traditional preprocessing changes. * doc/cpp.texi: Update for traditional preprocessing changes. * goc/cppopts.texi: Similarly. From-SVN: r55194 --- gcc/ChangeLog | 5 + gcc/doc/cpp.texi | 305 ++++++++++++++++++++++++++++++------------- gcc/doc/cppopts.texi | 8 +- 3 files changed, 225 insertions(+), 93 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 18bbcdbfd07..82d5964f06f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2002-07-02 Neil Booth + + * doc/cpp.texi: Update for traditional preprocessing changes. + * goc/cppopts.texi: Similarly. + 2002-07-02 Ziemowit Laski * c-parse.in (designator): Enable designated initializers if ObjC. diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi index a7f3cd2e8db..5b7d08ed1d1 100644 --- a/gcc/doc/cpp.texi +++ b/gcc/doc/cpp.texi @@ -204,7 +204,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. @@ -275,8 +275,8 @@ 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. These are nine three-character sequences, all starting with @samp{??}, that are defined by ISO C to stand for single characters. They permit @@ -1779,9 +1779,9 @@ 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. +@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 @@ -1806,8 +1806,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 @@ -2141,13 +2141,15 @@ f (1 f) @end smallexample -@noindent which expands to +@noindent +which expands to @smallexample 1 2 1 2 @end smallexample -@noindent with the semantics described above. +@noindent +with the semantics described above. @node Macro Pitfalls @section Macro Pitfalls @@ -3334,91 +3336,225 @@ 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. As of GCC 3.2, traditional mode is not supported for -compilation, only preprocessing. +GCC versions 3.2 and later only support traditional mode semantics in +the preprocessor, and not in the compiler. This chapter outlines the +semantics we implemented in the traditional preprocessor that is +integrated into the compiler front end. -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 +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. + +@menu +* Traditional lexical analysis:: +* Traditional macros:: +* Traditional miscellany:: +* Traditional warnings:: +@end menu + +@node Traditional lexical analysis +@section Traditional lexical analysis + +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 form imposed on it. + +This implementation does not treat trigraphs (@pxref{trigraphs}) +specially since they were created later during standardization. It +handles arbitrarily-positioned escaped newlines properly and splices +the lines as you would expect; many traditional preprocessors did not +do this. + +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. + +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 @samp{<} in a @code{#include} directive. + +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, comments can effectively be used as +token paste operators. However, comments behave like separators for +text handled by the preprocessor itself. For example, in + +@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