From: Neil Booth Date: Tue, 2 Jul 2002 22:20:33 +0000 (+0000) Subject: cpp.texi: Update for traditional preprocessing changes. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b6fb43ab3e59a0a4d9063daed96812eeb5a9fb47;p=platform%2Fupstream%2Fgcc.git cpp.texi: Update for traditional preprocessing changes. * doc/cpp.texi: Update for traditional preprocessing changes. * goc/cppopts.texi: Similarly. From-SVN: r55194 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 18bbcdb..82d5964 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 a7f3cd2..5b7d08e 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 -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 form imposed on it. -@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 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. -@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 @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, comments can effectively be used as +token paste operators. However, comments behave like separators for +text handled by the preprocessor itself. For example, in -@item -The @samp{#} and @samp{##} operators are not available in traditional -C@. +@smallexample +#if foo/**/bar +@end smallexample -@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@. +@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