Commit 5ef865d5 by Zack Weinberg Committed by Zack Weinberg

cppexp.c, [...]: Do not use 'legal' or 'illegal' in error messages and comments.

	* cppexp.c, cppinit.c, cpplex.c, cpplib.c, cppmacro.c,
	cppspec.c: Do not use 'legal' or 'illegal' in error messages
	and comments.

	* cppmain.c (cb_define, cb_undef): Don't generate any output
	if not done_initializing.
	* cpplex.c (maybe_paste_with_next): When the token after a ##
	is an omitted rest argument, only delete the token before it
	if that token is a comma.  Do not warn about bogus token
	pastes for , ## rest_arg.

	* cpp.texi: Update.
	* cpp.1: Regenerate.

	* gcc.dg/cpp/macsyntx.c: Fix error regexp.

From-SVN: r35421
parent a7a4fd17
2000-08-02 Zack Weinberg <zack@wolery.cumb.org>
* cppexp.c, cppinit.c, cpplex.c, cpplib.c, cppmacro.c,
cppspec.c: Do not use 'legal' or 'illegal' in error messages
and comments.
* cppmain.c (cb_define, cb_undef): Don't generate any output
if not done_initializing.
* cpplex.c (maybe_paste_with_next): When the token after a ##
is an omitted rest argument, only delete the token before it
if that token is a comma. Do not warn about bogus token
pastes for , ## rest_arg.
* cpp.texi: Update.
* cpp.1: Regenerate.
2000-08-02 Fred Fish <fnf@be.com> 2000-08-02 Fred Fish <fnf@be.com>
* config/i386/beos-elf.h (STARTFILE_SPEC): Add i386-mcount.o * config/i386/beos-elf.h (STARTFILE_SPEC): Add i386-mcount.o
......
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
.ds T' ' .ds T' '
.ds PI \(*p .ds PI \(*p
'br\} 'br\}
.TH CPP 1 "gcc-2.95" "14/Jun/99" "GNU" .TH CPP 1 "gcc-3.0" "1/Aug/2000" "GNU"
.UC .UC
.if n .hy 0 .if n .hy 0
.if n .na .if n .na
...@@ -181,13 +181,20 @@ cpp [\fB\-P\fR] [\fB\-C\fR] [\fB\-gcc\fR] [\fB\-traditional\fR] ...@@ -181,13 +181,20 @@ cpp [\fB\-P\fR] [\fB\-C\fR] [\fB\-gcc\fR] [\fB\-traditional\fR]
.PP .PP
Only the most useful options are listed here; see below for the remainder. Only the most useful options are listed here; see below for the remainder.
.SH "DESCRIPTION" .SH "DESCRIPTION"
The C preprocessor is a \fImacro processor\fR that is used automatically by The C preprocessor is a \fImacro processor\fR that is used automatically
the C compiler to transform your program before actual compilation. It is by the C compiler to transform your program before actual compilation.
called a macro processor because it allows you to define \fImacros\fR, It is called a macro processor because it allows you to define
which are brief abbreviations for longer constructs. \fImacros\fR, which are brief abbreviations for longer constructs.
.PP .PP
The C preprocessor provides four separate facilities that you can use as The C preprocessor is intended only for macro processing of C, \*(C+ and
you see fit: Objective C source files. For macro processing of other files, you are
strongly encouraged to use alternatives like M4, which will likely give
you better results and avoid many problems. For example, normally the C
preprocessor does not preserve arbitrary whitespace verbatim, but
instead replaces each sequence with a single space.
.PP
For use on C\-like source files, the C preprocessor provides four
separate facilities that you can use as you see fit:
.Ip "\(bu" 4 .Ip "\(bu" 4
Inclusion of header files. These are files of declarations that can be Inclusion of header files. These are files of declarations that can be
substituted into your program. substituted into your program.
...@@ -200,32 +207,27 @@ Conditional compilation. Using special preprocessing directives, you ...@@ -200,32 +207,27 @@ Conditional compilation. Using special preprocessing directives, you
can include or exclude parts of the program according to various can include or exclude parts of the program according to various
conditions. conditions.
.Ip "\(bu" 4 .Ip "\(bu" 4
Line control. If you use a program to combine or rearrange source files into Line control. If you use a program to combine or rearrange source files
an intermediate file which is then compiled, you can use line control into an intermediate file which is then compiled, you can use line
to inform the compiler of where each source line originally came from. control to inform the compiler of where each source line originally came
from.
.PP .PP
C preprocessors vary in some details. This manual discusses the \s-1GNU\s0 C C preprocessors vary in some details. This manual discusses the \s-1GNU\s0 C
preprocessor, the C Compatible Compiler Preprocessor. The \s-1GNU\s0 C preprocessor, which provides a small superset of the features of \s-1ISO\s0
preprocessor provides a superset of the features of \s-1ANSI\s0 Standard C. Standard C.
.PP
\s-1ANSI\s0 Standard C requires the rejection of many harmless constructs commonly
used by today's C programs. Such incompatibility would be inconvenient for
users, so the \s-1GNU\s0 C preprocessor is configured to accept these constructs
by default. Strictly speaking, to get \s-1ANSI\s0 Standard C, you must use the
options \fB\-trigraphs\fR, \fB\-undef\fR and \fB\-pedantic\fR, but in
practice the consequences of having strict \s-1ANSI\s0 Standard C make it
undesirable to do this.
.PP .PP
The C preprocessor is designed for C\-like languages; you may run into In its default mode, the \s-1GNU\s0 C preprocessor does not do a few things
problems if you apply it to other kinds of languages, because it assumes required by the standard. These are features which are rarely, if ever,
that it is dealing with C. For example, the C preprocessor sometimes used, and may cause surprising changes to the meaning of a program which
outputs extra white space to avoid inadvertent C token concatenation, does not expect them. To get strict \s-1ISO\s0 Standard C, you should use the
and this may cause problems with other languages. \fB\-std=c89\fR or \fB\-std=c99\fR options, depending on which version
of the standard you want. To get all the mandatory diagnostics, you
must also use \fB\-pedantic\fR.
.SH "OPTIONS" .SH "OPTIONS"
The C preprocessor expects two file names as arguments, \fIinfile\fR and The C preprocessor expects two file names as arguments, \fIinfile\fR and
\fIoutfile\fR. The preprocessor reads \fIinfile\fR together with any other \fIoutfile\fR. The preprocessor reads \fIinfile\fR together with any
files it specifies with \fB#include\fR. All the output generated by the other files it specifies with \fB#include\fR. All the output generated
combined input files is written in \fIoutfile\fR. by the combined input files is written in \fIoutfile\fR.
.PP .PP
Either \fIinfile\fR or \fIoutfile\fR may be \fB\-\fR, which as Either \fIinfile\fR or \fIoutfile\fR may be \fB\-\fR, which as
\fIinfile\fR means to read from standard input and as \fIoutfile\fR \fIinfile\fR means to read from standard input and as \fIoutfile\fR
...@@ -237,61 +239,69 @@ These options can also be given when compiling a C program; they are ...@@ -237,61 +239,69 @@ These options can also be given when compiling a C program; they are
passed along automatically to the preprocessor when it is invoked by the passed along automatically to the preprocessor when it is invoked by the
compiler. compiler.
.Ip "\fB\-P\fR" 4 .Ip "\fB\-P\fR" 4
Inhibit generation of \fB#\fR\-lines with line-number information in Inhibit generation of \fB#\fR\-lines with line-number information in the
the output from the preprocessor This might be output from the preprocessor. This might be useful when running the
useful when running the preprocessor on something that is not C code preprocessor on something that is not C code and will be sent to a
and will be sent to a program which might be confused by the program which might be confused by the \fB#\fR\-lines.
\fB#\fR\-lines.
.Ip "\fB\-C\fR" 4 .Ip "\fB\-C\fR" 4
Do not discard comments: pass them through to the output file. Do not discard comments. All comments are passed through to the output
Comments appearing in arguments of a macro call will be copied to the file, except for comments in processed directives, which are deleted
output before the expansion of the macro call. along with the directive. Comments appearing in the expansion list of a
macro will be preserved, and appear in place wherever the macro is
invoked.
.Sp
You should be prepared for side effects when using \fB\-C\fR; it causes
the preprocessor to treat comments as tokens in their own right. For
example, macro redefinitions that were trivial when comments were
replaced by a single space might become significant when comments are
retained. Also, comments appearing at the start of what would be a
directive line have the effect of turning that line into an ordinary
source line, since the first token on the line is no longer a \fB#\fR.
.Ip "\fB\-traditional\fR" 4 .Ip "\fB\-traditional\fR" 4
Try to imitate the behavior of old-fashioned C, as opposed to \s-1ANSI\s0 C. Try to imitate the behavior of old-fashioned C, as opposed to \s-1ISO\s0 C.
.Ip "\(bu" 8 .RS 4
Traditional macro expansion pays no attention to singlequote or .Ip "\(bu" 4
doublequote characters; macro argument symbols are replaced by the 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 argument values even when they appear within apparent string or
character constants. character constants.
.Ip "\(bu" 8 .Ip "\(bu" 4
Traditionally, it is permissible for a macro expansion to end in the Traditionally, it is permissible for a macro expansion to end in the
middle of a string or character constant. The constant continues into middle of a string or character constant. The constant continues into
the text surrounding the macro call. the text surrounding the macro call.
.Ip "\(bu" 8 .Ip "\(bu" 4
However, traditionally the end of the line terminates a string or However, traditionally the end of the line terminates a string or
character constant, with no error. character constant, with no error.
.Ip "\(bu" 8 .Ip "\(bu" 4
In traditional C, a comment is equivalent to no text at all. (In \s-1ANSI\s0 In traditional C, a comment is equivalent to no text at all. (In \s-1ISO\s0
C, a comment counts as whitespace.) C, a comment counts as whitespace.)
.Ip "\(bu" 8 .Ip "\(bu" 4
Traditional C does not have the concept of a ``preprocessing number'\*(R'. Traditional C does not have the concept of a ``preprocessing number'\*(R'.
It considers \fB1.0e+4\fR to be three tokens: \fB1.0e\fR, \fB+\fR, It considers \fB1.0e+4\fR to be three tokens: \fB1.0e\fR, \fB+\fR,
and \fB4\fR. and \fB4\fR.
.Ip "\(bu" 8 .Ip "\(bu" 4
A macro is not suppressed within its own definition, in traditional C. A macro is not suppressed within its own definition, in traditional C.
Thus, any macro that is used recursively inevitably causes an error. Thus, any macro that is used recursively inevitably causes an error.
.Ip "\(bu" 8 .Ip "\(bu" 4
The character \fB#\fR has no special meaning within a macro definition The character \fB#\fR has no special meaning within a macro definition
in traditional C. in traditional C.
.Ip "\(bu" 8 .Ip "\(bu" 4
In traditional C, the text at the end of a macro expansion can run 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. together with the text after the macro call, to produce a single token.
(This is impossible in \s-1ANSI\s0 C.) (This is impossible in \s-1ISO\s0 C.)
.Ip "\(bu" 8 .Ip "\(bu" 4
Traditionally, \fB\e\fR inside a macro argument suppresses the syntactic None of the \s-1GNU\s0 extensions to the preprocessor are available in
significance of the following character. \fB\-traditional\fR mode.
.Sp .RE
Use the \fB\-traditional\fR option when preprocessing Fortran code, .Ip "" 4
so that singlequotes and doublequotes Use the \fB\-traditional\fR option when preprocessing Fortran code, so
within Fortran comment lines that single-quotes and double-quotes within Fortran comment lines (which
(which are generally not recognized as such by the preprocessor) are generally not recognized as such by the preprocessor) do not cause
do not cause diagnostics diagnostics about unterminated character or string constants.
about unterminated character or string constants.
.Sp .Sp
However, this option does not prevent diagnostics However, this option does not prevent diagnostics about unterminated
about unterminated comments comments when a C\-style comment appears to start, but not end, within
when a C\-style comment appears to start, but not end, Fortran-style commentary.
within Fortran-style commentary.
.Sp .Sp
So, the following Fortran comment lines are accepted with So, the following Fortran comment lines are accepted with
\fB\-traditional\fR: \fB\-traditional\fR:
...@@ -301,49 +311,77 @@ So, the following Fortran comment lines are accepted with ...@@ -301,49 +311,77 @@ So, the following Fortran comment lines are accepted with
\& C Neither is "20000000000, an octal constant \& C Neither is "20000000000, an octal constant
\& C in some dialects of Fortran \& C in some dialects of Fortran
.Ve .Ve
However, this type of comment line will likely produce a diagnostic, However, this type of comment line will likely produce a diagnostic, or
or at least unexpected output from the preprocessor, at least unexpected output from the preprocessor, due to the
due to the unterminated comment: unterminated comment:
.Sp .Sp
.Vb 2 .Vb 2
\& C Some Fortran compilers accept /* as starting \& C Some Fortran compilers accept /* as starting
\& C an inline comment. \& C an inline comment.
.Ve .Ve
Note that \f(CWg77\fR automatically supplies Note that \f(CWg77\fR automatically supplies the \fB\-traditional\fR
the \fB\-traditional\fR option option when it invokes the preprocessor. However, a future version of
when it invokes the preprocessor. \f(CWg77\fR might use a different, more-Fortran-aware preprocessor in
However, a future version of \f(CWg77\fR place of \f(CWcpp\fR.
might use a different, more-Fortran-aware preprocessor
in place of \f(CWcpp\fR.
.Ip "\fB\-trigraphs\fR" 4 .Ip "\fB\-trigraphs\fR" 4
Process \s-1ANSI\s0 standard trigraph sequences. These are three-character Process \s-1ISO\s0 standard trigraph sequences. These are three-character
sequences, all starting with \fB??\fR, that are defined by \s-1ANSI\s0 C to sequences, all starting with \fB??\fR, that are defined by \s-1ISO\s0 C to
stand for single characters. For example, \fB??/\fR stands for stand for single characters. For example, \fB??/\fR stands for
\fB\e\fR, so \fB\*(R'??/n\*(R'\fR is a character constant for a newline. \fB\e\fR, so \fB\*(R'??/n\*(R'\fR is a character constant for a newline. By
Strictly speaking, the \s-1GNU\s0 C preprocessor does not support all default, \s-1GCC\s0 ignores trigraphs, but in standard-conforming modes it
programs in \s-1ANSI\s0 Standard C unless \fB\-trigraphs\fR is used, but if converts them. See the \fB\-std\fR option.
you ever notice the difference it will be with relief.
.Sp .Sp
You don't want to know any more about trigraphs. The nine trigraph sequences are
.RS 4
.PD 0
.SP
.Ip "\fB??(\fR" 6
-> \fB[\fR
.Ip "\fB??)\fR" 6
-> \fB]\fR
.Ip "\fB??<\fR" 6
-> \fB@{\fR
.Ip "\fB??>\fR" 6
-> \fB@\fR}
.Ip "\fB??=\fR" 6
-> \fB#\fR
.Ip "\fB??/\fR" 6
-> \fB\e\fR
.Ip "\fB??\*(T'\fR" 6
-> \fB^\fR
.Ip "\fB??!\fR" 6
-> \fB|\fR
.Ip "\fB??\-\fR" 6
-> \fB~\fR
.RE
.PD
.Ip "" 4
Trigraph support is not popular, so many compilers do not implement it
properly. Portable code should not rely on trigraphs being either
converted or ignored.
.Ip "\fB\-pedantic\fR" 4 .Ip "\fB\-pedantic\fR" 4
Issue warnings required by the \s-1ANSI\s0 C standard in certain cases such Issue warnings required by the \s-1ISO\s0 C standard in certain cases such
as when text other than a comment follows \fB#else\fR or \fB#endif\fR. as when text other than a comment follows \fB#else\fR or \fB#endif\fR.
.Ip "\fB\-pedantic-errors\fR" 4 .Ip "\fB\-pedantic-errors\fR" 4
Like \fB\-pedantic\fR, except that errors are produced rather than Like \fB\-pedantic\fR, except that errors are produced rather than
warnings. warnings.
.Ip "\fB\-Wtrigraphs\fR" 4
Warn if any trigraphs are encountered. Currently this only works if you
have turned trigraphs on with \fB\-trigraphs\fR or \fB\-ansi\fR; in the
future this restriction will be removed.
.Ip "\fB\-Wcomment\fR" 4 .Ip "\fB\-Wcomment\fR" 4
.Ip "\fB\-Wcomments\fR" 4
(Both forms have the same effect).
Warn whenever a comment-start sequence \fB/*\fR appears in a \fB/*\fR Warn whenever a comment-start sequence \fB/*\fR appears in a \fB/*\fR
comment, or whenever a Backslash-Newline appears in a \fB//\fR comment. comment, or whenever a backslash-newline appears in a \fB//\fR comment.
.Ip "\fB\-Wtrigraphs\fR" 4
Warn if any trigraphs are encountered. This option used to take effect
only if \fB\-trigraphs\fR was also specified, but now works independently.
.Ip "\fB\-Wwhite-space\fR" 4
Warn about possible white space confusion, e.g. white space between a
backslash and a newline.
.Ip "\fB\-Wall\fR" 4 .Ip "\fB\-Wall\fR" 4
Requests both \fB\-Wtrigraphs\fR and \fB\-Wcomment\fR (but not Requests \fB\-Wcomment\fR, \fB\-Wtrigraphs\fR, and \fB\-Wwhite-space\fR
\fB\-Wtraditional\fR or \fB\-Wundef\fR). (but not \fB\-Wtraditional\fR or \fB\-Wundef\fR).
.Ip "\fB\-Wtraditional\fR" 4 .Ip "\fB\-Wtraditional\fR" 4
Warn about certain constructs that behave differently in traditional and Warn about certain constructs that behave differently in traditional and
\s-1ANSI\s0 C. \s-1ISO\s0 C.
.Ip "\fB\-Wundef\fR" 4 .Ip "\fB\-Wundef\fR" 4
Warn if an undefined identifier is evaluated in an \fB#if\fR directive. Warn if an undefined identifier is evaluated in an \fB#if\fR directive.
.Ip "\fB\-I \fIdirectory\fR\fR" 4 .Ip "\fB\-I \fIdirectory\fR\fR" 4
...@@ -356,15 +394,15 @@ the directories are scanned in left-to-right order; the standard ...@@ -356,15 +394,15 @@ the directories are scanned in left-to-right order; the standard
system directories come after. system directories come after.
.Ip "\fB\-I-\fR" 4 .Ip "\fB\-I-\fR" 4
Any directories specified with \fB\-I\fR options before the \fB\-I-\fR Any directories specified with \fB\-I\fR options before the \fB\-I-\fR
option are searched only for the case of \fB#include \*(L"\fIfile\fB\*(R"\fR; option are searched only for the case of \fB#include \*(L"\fIfile\fR\*(R"\fR;
they are not searched for \fB#include <\fIfile\fB>\fR. they are not searched for \fB#include <\fIfile\fR>\fR.
.Sp .Sp
If additional directories are specified with \fB\-I\fR options after If additional directories are specified with \fB\-I\fR options after
the \fB\-I-\fR, these directories are searched for all \fB#include\fR the \fB\-I-\fR, these directories are searched for all \fB#include\fR
directives. directives.
.Sp .Sp
In addition, the \fB\-I-\fR option inhibits the use of the current In addition, the \fB\-I-\fR option inhibits the use of the current
directory as the first search directory for \fB#include \*(L"\fIfile\fB\*(R"\fR. directory as the first search directory for \fB#include \*(L"\fIfile\fR\*(R"\fR.
Therefore, the current directory is searched only if it is requested Therefore, the current directory is searched only if it is requested
explicitly with \fB\-I.\fR. Specifying both \fB\-I-\fR and \fB\-I.\fR explicitly with \fB\-I.\fR. Specifying both \fB\-I-\fR and \fB\-I.\fR
allows you to control precisely which directories are searched before allows you to control precisely which directories are searched before
...@@ -375,8 +413,8 @@ Only the directories you have specified with \fB\-I\fR options ...@@ -375,8 +413,8 @@ Only the directories you have specified with \fB\-I\fR options
(and the current directory, if appropriate) are searched. (and the current directory, if appropriate) are searched.
.Ip "\fB\-nostdinc++\fR" 4 .Ip "\fB\-nostdinc++\fR" 4
Do not search for header files in the \*(C+\-specific standard directories, Do not search for header files in the \*(C+\-specific standard directories,
but do still search the other standard directories. but do still search the other standard directories. (This option is
(This option is used when building the \*(C+ library.) used when building the \*(C+ library.)
.Ip "\fB\-remap\fR" 4 .Ip "\fB\-remap\fR" 4
When searching for a header file in a directory, remap file names if a When searching for a header file in a directory, remap file names if a
file named \fIheader.gcc\fR exists in that directory. This can be used file named \fIheader.gcc\fR exists in that directory. This can be used
...@@ -402,15 +440,17 @@ wins. ...@@ -402,15 +440,17 @@ wins.
Do not predefine any nonstandard macros. Do not predefine any nonstandard macros.
.Ip "\fB\-gcc\fR" 4 .Ip "\fB\-gcc\fR" 4
Define the macros \fI_\|_GNUC_\|_\fR, \fI_\|_GNUC_MINOR_\|_\fR and Define the macros \fI_\|_GNUC_\|_\fR, \fI_\|_GNUC_MINOR_\|_\fR and
\fI_\|_GNUC_PATCHLEVEL_\|_\fR. These are defined automatically when you \fI_\|_GNUC_PATCHLEVEL_\|_\fR. These are defined automatically when you use
use \fBgcc \-E\fR; you can turn them off in that case with \fB\-no-gcc\fR. \fBgcc \-E\fR; you can turn them off in that case with \fB\-no-gcc\fR.
.Ip "\fB\-A \fIpredicate\fR(\fIanswer\fR)\fR" 4 .Ip "\fB\-A \fIpredicate\fR(\fIanswer\fR)\fR" 4
Make an assertion with the predicate \fIpredicate\fR and answer Make an assertion with the predicate \fIpredicate\fR and answer
\fIanswer\fR. \fIanswer\fR.
.Sp .Ip "\fB\-A \-\fIpredicate\fR(\fIanswer\fR)\fR" 4
You can use \fB\-A-\fR to disable all predefined assertions; it also Disable an assertion with the predicate \fIpredicate\fR and answer
undefines all predefined macros and all macros that preceded it on the \fIanswer\fR. Specifying no predicate, by \fB\-A-\fR or \fB\-A \-\fR,
command line. disables all predefined assertions and all assertions preceding it on
the command line; and also undefines all predefined macros and all
macros preceding it on the command line.
.Ip "\fB\-dM\fR" 4 .Ip "\fB\-dM\fR" 4
Instead of outputting the result of preprocessing, output a list of Instead of outputting the result of preprocessing, output a list of
\fB#define\fR directives for all the macros defined during the \fB#define\fR directives for all the macros defined during the
...@@ -427,19 +467,22 @@ Like \fB\-dM\fR except in two respects: it does \fInot\fR include the ...@@ -427,19 +467,22 @@ Like \fB\-dM\fR except in two respects: it does \fInot\fR include the
predefined macros, and it outputs \fIboth\fR the \fB#define\fR predefined macros, and it outputs \fIboth\fR the \fB#define\fR
directives and the result of preprocessing. Both kinds of output go to directives and the result of preprocessing. Both kinds of output go to
the standard output file. the standard output file.
.Ip "\fB\-dN\fR" 4
Like \fB\-dD\fR, but emit only the macro names, not their expansions.
.Ip "\fB\-dI\fR" 4 .Ip "\fB\-dI\fR" 4
Output \fB#include\fR directives in addition to the result of preprocessing. Output \fB#include\fR directives in addition to the result of
preprocessing.
.Ip "\fB\-M [\-\s-1MG\s0]\fR" 4 .Ip "\fB\-M [\-\s-1MG\s0]\fR" 4
Instead of outputting the result of preprocessing, output a rule Instead of outputting the result of preprocessing, output a rule
suitable for \f(CWmake\fR describing the dependencies of the main suitable for \f(CWmake\fR describing the dependencies of the main source
source file. The preprocessor outputs one \f(CWmake\fR rule containing file. The preprocessor outputs one \f(CWmake\fR rule containing the
the object file name for that source file, a colon, and the names of object file name for that source file, a colon, and the names of all the
all the included files. If there are many included files then the included files. If there are many included files then the rule is split
rule is split into several lines using \fB\e\fR\-newline. into several lines using \fB\e\fR\-newline.
.Sp .Sp
\fB\-\s-1MG\s0\fR says to treat missing header files as generated files and assume \fB\-\s-1MG\s0\fR says to treat missing header files as generated files and
they live in the same directory as the source file. It must be specified assume they live in the same directory as the source file. It must be
in addition to \fB\-M\fR. specified in addition to \fB\-M\fR.
.Sp .Sp
This feature is used in automatic updating of makefiles. This feature is used in automatic updating of makefiles.
.Ip "\fB\-\s-1MM\s0 [\-\s-1MG\s0]\fR" 4 .Ip "\fB\-\s-1MM\s0 [\-\s-1MG\s0]\fR" 4
...@@ -448,16 +491,16 @@ Like \fB\-M\fR but mention only the files included with \fB#include ...@@ -448,16 +491,16 @@ Like \fB\-M\fR but mention only the files included with \fB#include
<\fIfile\fR>\fR are omitted. <\fIfile\fR>\fR are omitted.
.Ip "\fB\-\s-1MD\s0 \fIfile\fR\fR" 4 .Ip "\fB\-\s-1MD\s0 \fIfile\fR\fR" 4
Like \fB\-M\fR but the dependency information is written to \fIfile\fR. Like \fB\-M\fR but the dependency information is written to \fIfile\fR.
This is in addition to compiling the file as specified---\fB\-\s-1MD\s0\fR does This is in addition to compiling the file as specified --- \fB\-\s-1MD\s0\fR
not inhibit ordinary compilation the way \fB\-M\fR does. does not inhibit ordinary compilation the way \fB\-M\fR does.
.Sp .Sp
When invoking \f(CWgcc\fR, do not specify the \fIfile\fR argument. When invoking \f(CWgcc\fR, do not specify the \fIfile\fR argument.
\f(CWgcc\fR will create file names made by replacing \*(L".c\*(R" with \*(L".d\*(R" at \f(CWgcc\fR will create file names made by replacing \*(L".c\*(R" with \*(L".d\*(R" at
the end of the input file names. the end of the input file names.
.Sp .Sp
In Mach, you can use the utility \f(CWmd\fR to merge multiple dependency In Mach, you can use the utility \f(CWmd\fR to merge multiple dependency
files into a single dependency file suitable for using with the \fBmake\fR files into a single dependency file suitable for using with the
command. \fBmake\fR command.
.Ip "\fB\-\s-1MMD\s0 \fIfile\fR\fR" 4 .Ip "\fB\-\s-1MMD\s0 \fIfile\fR\fR" 4
Like \fB\-\s-1MD\s0\fR except mention only user header files, not system Like \fB\-\s-1MD\s0\fR except mention only user header files, not system
header files. header files.
...@@ -480,15 +523,16 @@ in any of the directories in the main include path (the one that ...@@ -480,15 +523,16 @@ in any of the directories in the main include path (the one that
\fB\-I\fR adds to). \fB\-I\fR adds to).
.Ip "\fB\-iprefix \fIprefix\fR\fR" 4 .Ip "\fB\-iprefix \fIprefix\fR\fR" 4
Specify \fIprefix\fR as the prefix for subsequent \fB\-iwithprefix\fR Specify \fIprefix\fR as the prefix for subsequent \fB\-iwithprefix\fR
options. options. If the prefix represents a directory, you should include the
final \fB/\fR.
.Ip "\fB\-iwithprefix \fIdir\fR\fR" 4 .Ip "\fB\-iwithprefix \fIdir\fR\fR" 4
Add a directory to the second include path. The directory's name is Add a directory to the second include path. The directory's name is
made by concatenating \fIprefix\fR and \fIdir\fR, where \fIprefix\fR made by concatenating \fIprefix\fR and \fIdir\fR, where \fIprefix\fR was
was specified previously with \fB\-iprefix\fR. specified previously with \fB\-iprefix\fR.
.Ip "\fB\-isystem \fIdir\fR\fR" 4 .Ip "\fB\-isystem \fIdir\fR\fR" 4
Add a directory to the beginning of the second include path, marking it Add a directory to the beginning of the second include path, marking it
as a system directory, so that it gets the same special treatment as as a system directory, so that it gets the same special treatment as
is applied to the standard system directories. is applied to the standard system directories.
.Ip "\fB\-x c\fR" 4 .Ip "\fB\-x c\fR" 4
.Ip "\fB\-x c++\fR" 4 .Ip "\fB\-x c++\fR" 4
.Ip "\fB\-x objective-c\fR" 4 .Ip "\fB\-x objective-c\fR" 4
...@@ -514,39 +558,52 @@ added in the future. ...@@ -514,39 +558,52 @@ added in the future.
.Sp .Sp
\fIstandard\fR \fIstandard\fR
may be one of: may be one of:
.Ip "\f(CWiso9899:1990\fR" 8 .RS 4
The \s-1ISO\s0 C standard from 1990. .PD 0
.Ip "\f(CWiso9899:199409\fR" 8 .Sp
.Ip "\f(CWc89\fR" 8 .Ip "\f(CWiso9899:1990\fR" 4
The 1990 C standard, as amended in 1994. \fBc89\fR is the customary .Ip "\f(CWc89\fR" 4
shorthand for this version of the standard. .Ip
The \s-1ISO\s0 C standard from 1990. \fBc89\fR is the customary shorthand for
this version of the standard.
.Sp .Sp
The \fB\-ansi\fR option is equivalent to \fB\-std=c89\fR. The \fB\-ansi\fR option is equivalent to \fB\-std=c89\fR.
.Ip "\f(CWiso9899:199x\fR" 8 .Sp
.Ip "\f(CWc9x\fR" 8 .Ip "\f(CWiso9899:199409\fR" 4
The revised \s-1ISO\s0 C standard, which is expected to be promulgated some The 1990 C standard, as amended in 1994.
time in 1999. It has not been approved yet, hence the \fBx\fR. .Sp
.Ip "\f(CWgnu89\fR" 8 .Ip "\f(CWiso9899:1999\fR" 4
.Ip "\f(CWc99\fR" 4
.Ip "\f(CWiso9899:199x\fR" 4
.Ip "\f(CWc9x\fR" 4
.Ip
The revised \s-1ISO\s0 C standard, published in December 1999. Before
publication, this was known as C9X.
.Sp
.Ip "\f(CWgnu89\fR" 4
The 1990 C standard plus \s-1GNU\s0 extensions. This is the default. The 1990 C standard plus \s-1GNU\s0 extensions. This is the default.
.Ip "\f(CWgnu9x\fR" 8
The 199x C standard plus \s-1GNU\s0 extensions.
.Ip "\fB\-Wp,\-lint\fR" 4
Look for commands to the program checker \f(CWlint\fR embedded in
comments, and emit them preceded by \fB#pragma lint\fR. For example,
the comment \fB/* \s-1NOTREACHED\s0 */\fR becomes \fB#pragma lint
\s-1NOTREACHED\s0\fR.
.Sp .Sp
Because of the clash with \fB\-l\fR, you must use the awkward syntax .Ip "\f(CWgnu99\fR" 4
above. In a future release, this option will be replaced by .Ip "\f(CWgnu9x\fR" 4
\fB\-flint\fR or \fB\-Wlint\fR; we are not sure which yet. The 1999 C standard plus \s-1GNU\s0 extensions.
.PD
.RE
.Ip "\fB\-ftabstop=\s-1NUMBER\s0\fR" 4
Set the distance between tabstops. This helps the preprocessor
report correct column numbers in warnings or errors, even if tabs appear
on the line. Values less than 1 or greater than 100 are ignored. The
default is 8.
.Ip "\fB\-$\fR" 4 .Ip "\fB\-$\fR" 4
Forbid the use of \fB$\fR in identifiers. The C standard does not Forbid the use of \fB$\fR in identifiers. The C standard allows
permit this, but it is a common extension. implementations to define extra characters that can appear in
identifiers. By default the \s-1GNU\s0 C preprocessor permits \fB$\fR, a
common extension.
.SH "SEE ALSO" .SH "SEE ALSO"
\fIgcc\fR\|(1), \fIas\fR\|(1), \fIld\fR\|(1), and the Info entries for \fIcpp\fR, \fIgcc\fR, and \fIgcc\fR\|(1), \fIas\fR\|(1), \fIld\fR\|(1), and the Info entries for \fIcpp\fR, \fIgcc\fR, and
\fIbinutils\fR. \fIbinutils\fR.
.SH "COPYRIGHT" .SH "COPYRIGHT"
Copyright 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999 Copyright 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996,
1997, 1998, 1999, 2000
Free Software Foundation, Inc. Free Software Foundation, Inc.
.PP .PP
Permission is granted to make and distribute verbatim copies of Permission is granted to make and distribute verbatim copies of
...@@ -560,4 +617,3 @@ permission notice identical to this one. ...@@ -560,4 +617,3 @@ permission notice identical to this one.
.PP .PP
Permission is granted to copy and distribute translations of this manual Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions. into another language, under the above conditions for modified versions.
.rn }` ''
...@@ -116,13 +116,13 @@ C preprocessors vary in some details. This manual discusses the GNU C ...@@ -116,13 +116,13 @@ C preprocessors vary in some details. This manual discusses the GNU C
preprocessor, which provides a small superset of the features of ISO preprocessor, which provides a small superset of the features of ISO
Standard C@. Standard C@.
ISO Standard C requires the rejection of many harmless constructs In its default mode, the GNU C preprocessor does not do a few things
commonly used by today's C programs. Such incompatibility would be required by the standard. These are features which are rarely, if ever,
inconvenient for users, so the GNU C preprocessor is configured to used, and may cause surprising changes to the meaning of a program which
accept these constructs by default. Strictly speaking, to get ISO does not expect them. To get strict ISO Standard C, you should use the
Standard C, you must use the options @samp{-trigraphs}, @samp{-undef} @samp{-std=c89} or @samp{-std=c99} options, depending on which version
and @samp{-pedantic}, but in practice the consequences of having strict of the standard you want. To get all the mandatory diagnostics, you
ISO Standard C make it undesirable to do this. @xref{Invocation}. must also use @samp{-pedantic}. @xref{Invocation}.
@c man end @c man end
...@@ -172,11 +172,10 @@ Predefined macro names are replaced with their expansions ...@@ -172,11 +172,10 @@ Predefined macro names are replaced with their expansions
(@pxref{Predefined}). (@pxref{Predefined}).
@end itemize @end itemize
The first three transformations are done @emph{before} nearly all other The first three transformations are done @emph{before} all other parsing
parsing and before preprocessing directives are recognized. Thus, for and before preprocessing directives are recognized. Thus, for example,
example, you can split a line cosmetically with backslash-newline you can split a line mechanically with backslash-newline anywhere
anywhere (except within trigraphs since they are replaced first; see (except within trigraphs since they are replaced first; see below).
below).
@example @example
/* /*
...@@ -188,39 +187,44 @@ O 10\ ...@@ -188,39 +187,44 @@ O 10\
@end example @end example
@noindent @noindent
is equivalent into @samp{#define FOO 1020}. You can split even an is equivalent into @samp{#define FOO 1020}.
escape sequence with backslash-newline. For example, you can split
@code{"foo\bar"} between the @samp{\} and the @samp{b} to get There is no way to prevent a backslash at the end of a line from being
interpreted as a backslash-newline. For example,
@example @example
"foo\\ "foo\\
bar" bar"
@end example @end example
@noindent is equivalent to @code{"foo\bar"}, not to @code{"foo\\bar"}. To avoid
This behavior can be confusing: in all other contexts, a backslash can having to worry about this, do not use the GNU extension which permits
be inserted in a string constant as an ordinary character by writing a multiline strings. Instead, use string constant concatenation:
double backslash. This is an exception, but the ISO C standard requires
it. (Strict ISO C does not allow string constants to extend to more @example
than one logical line, so they do not consider this a problem.) "foo\\"
"bar"
@end example
Your program will be more portable this way, too.
There are a few exceptions to all three transformations. There are a few exceptions to all three transformations.
@itemize @bullet @itemize @bullet
@item @item
C comments and predefined macro names are not recognized inside a Comments and predefined macro names (or any macro names, for that
@samp{#include} directive in which the file name is delimited with matter) are not recognized inside the argument of an @samp{#include}
@samp{<} and @samp{>}. What lies in-between is read literally. directive, whether it is delimited with quotes or with @samp{<} and
@samp{>}.
@item @item
C comments and predefined macro names are never recognized within a Comments and predefined macro names are never recognized within a
character or string constant. (Strictly speaking, this is the rule, character or string constant. (Strictly speaking, this is the rule,
not an exception, but it is worth noting here anyway.) not an exception, but it is worth noting here anyway.)
@item @item
Backslash-newline may not safely be used within an ISO ``trigraph'', ISO ``trigraphs'' are converted before backslash-newlines are deleted.
since trigraphs are converted before backslash-newlines are deleted. If If you write what looks like a trigraph with a backslash-newline inside,
you write what looks like a trigraph with a backslash-newline inside,
the backslash-newline is deleted as usual, but it is then too late to the backslash-newline is deleted as usual, but it is then too late to
recognize the trigraph. recognize the trigraph.
...@@ -234,7 +238,7 @@ are referring not to the two-character escape sequence "\0", but to the ...@@ -234,7 +238,7 @@ are referring not to the two-character escape sequence "\0", but to the
single character ASCII NUL. single character ASCII NUL.
There are three different contexts in which a null character may There are three different contexts in which a null character may
appear:- appear:
@itemize @bullet @itemize @bullet
@item @item
...@@ -367,13 +371,6 @@ for header files with the command option @samp{-I} (@pxref{Invocation}). ...@@ -367,13 +371,6 @@ for header files with the command option @samp{-I} (@pxref{Invocation}).
The option @samp{-nostdinc} inhibits searching the standard system The option @samp{-nostdinc} inhibits searching the standard system
directories; in this case only the directories you specify are searched. directories; in this case only the directories you specify are searched.
The parsing of this form of @samp{#include} is slightly special because
comments are not recognized within the @samp{<@dots{}>}. Thus, in
@samp{#include <x/*y>} the @samp{/*} does not start a comment and the
directive specifies inclusion of a system header file named @file{x/*y}.
Of course, a header file with such a name is unlikely to exist on Unix,
where shell wildcard features would make it hard to manipulate.@refill
The first @samp{>} character terminates the file name. The file name The first @samp{>} character terminates the file name. The file name
may contain a @samp{<} character. may contain a @samp{<} character.
...@@ -384,14 +381,21 @@ same directories used for system header files. The current directory is ...@@ -384,14 +381,21 @@ same directories used for system header files. The current directory is
the directory of the current input file. It is tried first because it the directory of the current input file. It is tried first because it
is presumed to be the location of the files that the current input file is presumed to be the location of the files that the current input file
refers to. (If the @samp{-I-} option is used, the special treatment of refers to. (If the @samp{-I-} option is used, the special treatment of
the current directory is inhibited.) the current directory is inhibited. @xref{Invocation}.)
The first @samp{"} character terminates the file name.
The first @samp{"} character terminates the file name. If backslashes In both these variants, the argument behaves like a string constant in
occur within @var{file}, they are considered ordinary text characters, that comments are not recognized, and macro names are not expanded.
not escape characters. None of the character escape sequences Thus, in @samp{#include <x/*y>} the @samp{/*} does not start a comment
appropriate to string constants in C are processed. Thus, and the directive specifies inclusion of a system header file named
@samp{#include "x\n\\y"} specifies a filename containing three @file{x/*y}.
backslashes.
However, in either variant, if backslashes occur within @var{file}, they
are considered ordinary text characters, not escape characters. None of
the character escape sequences appropriate to string constants in C are
processed. Thus, @samp{#include "x\n\\y"} specifies a filename
containing three backslashes.
@item #include @var{anything else} @item #include @var{anything else}
@cindex computed @samp{#include} @cindex computed @samp{#include}
...@@ -915,22 +919,44 @@ eprintf ("%s:%d: ", input_file_name, line_number) ...@@ -915,22 +919,44 @@ eprintf ("%s:%d: ", input_file_name, line_number)
fprintf (stderr, "%s:%d: " , input_file_name, line_number) fprintf (stderr, "%s:%d: " , input_file_name, line_number)
@end example @end example
We might instead have defined eprintf as follows:- Within a @samp{#define} directive, ISO C mandates that the only place
the identifier @code{__VA_ARGS__} can appear is in the replacement list
of a variable-argument macro. It may not be used as a macro name, macro
argument name, or within a different type of macro. It may also be
forbidden in open text; the standard is ambiguous. We recommend you
avoid using it except for its defined purpose.
If your macro is complicated, you may want a more descriptive name for
the variable argument than @code{__VA_ARGS__}. GNU 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
@example
#define eprintf(args...) fprintf (stderr, args)
@end example
@noindent
using this extension. You cannot use @code{__VA_ARGS__} and this
extension in the same macro.
We might instead have defined eprintf as follows:
@example @example
#define eprintf(format, ...) fprintf (stderr, format, __VA_ARGS__) #define eprintf(format, ...) fprintf (stderr, format, __VA_ARGS__)
@end example @end example
This formulation looks more descriptive, but unfortunately causes This formulation looks more descriptive, but cannot be used as flexibly.
problems if fprintf wants no arguments the format. There is no way to There is no way to produce expanded output of
produce expanded output of
@example @example
fprintf (stderr, "success!\n") fprintf (stderr, "success!\n")
@end example @end example
@noindent @noindent
since passing an empty argument for the variable arguments part like this because, in standard C, you are not allowed to leave the variable
argument out entirely, and passing an empty argument for the variable
arguments will not do what you want. Writing
@example @example
eprintf ("success!\n", ) eprintf ("success!\n", )
...@@ -947,28 +973,29 @@ fprintf (stderr, "success!\n",) ...@@ -947,28 +973,29 @@ fprintf (stderr, "success!\n",)
where the extra comma originates from the replacement list and not from where the extra comma originates from the replacement list and not from
the arguments to eprintf. the arguments to eprintf.
Within a @samp{#define} directive, ISO C mandates that the only place There is another extension in the GNU C preprocessor which deals with
the identifier @code{__VA_ARGS__} can appear is in the replacement list this difficulty. First, you are allowed to leave the variable argument
of a variable-argument macro. Using it as a macro name, macro argument out entirely:
or within a different type of macro is illegal.
@example
eprintf ("success!\n")
@end example
Before standardization, previous GNU preprocessors implemented a Second, the @samp{##} token paste operator has a special meaning when
slightly different syntax for defining variable-argument macros. The placed between a comma and a variable argument. If you write
macros were called ``rest args macros''. You could assign a name to the
variable arguments, by contrast the standardized method leaves them
anonymous. For example, the eprintf macro could have been defined like
this
@example @example
#define eprintf(format...) fprintf (stderr, format) #define eprintf(format, ...) fprintf (stderr, format, ##__VA_ARGS__)
@end example @end example
Now that there is a standardized construct, you are encouraged to use and the variable argument is left out when the @samp{eprintf} macro is
that instead. It is unlikely that support for named variable arguments used, then the comma before the @samp{##} will be deleted. This does
will be removed in future revisions of CPP, since being able to assign a @emph{not} happen if you pass an empty argument, nor does it happen if
name is descriptive, and there is a wide base of legacy code. However, the token preceding @samp{##} is anything other than a comma.
two obscure features of the GNU style are deprecated and likely to be
dropped in future. @xref{Unreliable Features}. Previous versions of the preprocessor implemented this extension much
more generally. We have restricted it in order to minimize the
difference from the C standard. @xref{Unreliable Features}.
@node Predefined, Stringification, Macro Varargs, Macros @node Predefined, Stringification, Macro Varargs, Macros
@subsection Predefined Macros @subsection Predefined Macros
...@@ -2790,42 +2817,52 @@ It is undefined which of these two operators is evaluated first. ...@@ -2790,42 +2817,52 @@ It is undefined which of these two operators is evaluated first.
@end itemize @end itemize
The following features are deprecated and will likely be removed at some The following features are in flux and should not be used in portable
point in the future:- code:
@itemize @bullet @itemize @bullet
@item ## swallowing the previous token in GNU rest argument macros @item Optional argument when invoking rest argument macros
In a macro expansion, if ## appeared before a GNU named variable arguments As an extension, GCC permits you to omit the variable arguments entirely
parameter, and the set of tokens specified for that argument in the when you use a variable argument macro. This works whether or not you
macro invocation was empty, previous versions of the GNU C preprocessor give the variable argument a name. For example, the two macro
would back up and remove the token appearing before the ##. This invocations in the example below expand to the same thing:
behavior was not well-defined, and alternative ways of achieving its
intended use are available. Since the ISO C standard now provides for
variable-argument macros, and since this old behavior potentially
conflicts with behavior mandated by the standard, this feature is now
deprecated and will be removed in future.
The current preprocessor still supports it for reasons of code @smallexample
migration, and warns at each use of the feature. #define debug(format, ...) printf (format, __VA_ARGS__)
debug("string"); /* Not permitted by C standard. */
debug("string",); /* OK. */
@end smallexample
@item Optional argument when invoking GNU rest argument macros This extension will be preserved, but the special behavior of @samp{##}
in this context has changed in the past and may change again in the
future.
In the invocation of a GNU named variable arguments macro, the variable @item ## swallowing preceding text in rest argument macros
arguments were optional. For example, the following two invocations are
both legal for GNU rest args. The first is illegal in the equivalent
formulation using ISO C anonymous variable arguments and
@code{__VA_ARGS__}:-
@smallexample Formerly, in a macro expansion, if @samp{##} appeared before a variable
#define debug(format, args...) printf (format, args) arguments parameter, and the set of tokens specified for that argument in
debug("string"); /* Illegal in ISO C equivalent. */ the macro invocation was empty, previous versions of the GNU C
debug("string",); /* OK for both. */ preprocessor would back up and remove the preceding sequence of
@end smallexample nonwhitespace characters (@strong{not} the preceding token). This
extension is in direct conflict with the 1999 C standard and has been
drastically pared back.
In the current version of the preprocessor, if @samp{##} appears between
a comma and a variable arguments parameter, and the variable argument is
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.
Portable code should avoid this extension at all costs.
@end itemize
The following features are deprecated and will likely be removed at some
point in the future:-
The current preprocessor still supports it for reasons of code @itemize @bullet
migration, and warns at each use of the feature.
@item Attempting to paste two tokens which together do not form a valid @item Attempting to paste two tokens which together do not form a valid
preprocessing token preprocessing token
...@@ -2834,6 +2871,10 @@ The preprocessor currently warns about this and outputs the two tokens ...@@ -2834,6 +2871,10 @@ The preprocessor currently warns about this and outputs the two tokens
adjacently, which is probably the behavior the programmer intends. It adjacently, which is probably the behavior the programmer intends. It
may not work in future, though. may not work in future, though.
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{##}.
@findex #pragma once @findex #pragma once
@item #pragma once @item #pragma once
...@@ -2849,7 +2890,33 @@ This pragma has been superceded by @samp{#pragma GCC poison}. ...@@ -2849,7 +2890,33 @@ This pragma has been superceded by @samp{#pragma GCC poison}.
@item Multi-line string literals in directives @item Multi-line string literals in directives
The GNU C preprocessor currently allows newlines in string literals The GNU C preprocessor currently allows newlines in string literals
within a directive. within a directive. This is forbidden by the C standard and will
eventually be removed. (Multi-line string literals in open text are
still supported.)
@item Preprocessing things which are not C
The C preprocessor is intended to be used only with C, C++, and
Objective C source code. In the past, it has been abused as a general
text processor. It will choke on input which is not lexically valid C;
for example, apostrophes will be interpreted as the beginning of
character constants, and cause errors. Also, you cannot rely on it
preserving characteristics of the input which are not significant to
C-family languages. For instance, if a Makefile is preprocessed, all
the hard tabs will be lost, 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, ...) and so is assembly, with caution. @samp{-traditional}
mode is much more permissive, and can safely be used with e.g. Fortran.
Many of the problems go away if you write C or C++ style comments
instead of native language comments, and if you avoid elaborate macros.
Wherever possible, you should use a preprocessor geared to the language
you are writing in. Modern versions of the GNU assembler have macro
facilities. Most high level programming languages have their own
conditional compilation and inclusion mechanism. If all else fails,
try a true general text processor, such as @xref{Top, M4, , m4, GNU `m4'}.
@end itemize @end itemize
...@@ -2900,11 +2967,10 @@ compiler. ...@@ -2900,11 +2967,10 @@ compiler.
@table @samp @table @samp
@item -P @item -P
@findex -P @findex -P
Inhibit generation of @samp{#}-lines with line-number information in Inhibit generation of @samp{#}-lines with line-number information in the
the output from the preprocessor (@pxref{Output}). This might be output from the preprocessor. This might be useful when running the
useful when running the preprocessor on something that is not C code preprocessor on something that is not C code and will be sent to a
and will be sent to a program which might be confused by the program which might be confused by the @samp{#}-lines. @xref{Output}.
@samp{#}-lines.
@item -C @item -C
@findex -C @findex -C
...@@ -2914,8 +2980,8 @@ along with the directive. Comments appearing in the expansion list of a ...@@ -2914,8 +2980,8 @@ along with the directive. Comments appearing in the expansion list of a
macro will be preserved, and appear in place wherever the macro is macro will be preserved, and appear in place wherever the macro is
invoked. invoked.
You should be prepared for side effects when using -C; it causes the You should be prepared for side effects when using @samp{-C}; it causes
preprocessor to treat comments as tokens in their own right. For the preprocessor to treat comments as tokens in their own right. For
example, macro redefinitions that were trivial when comments were example, macro redefinitions that were trivial when comments were
replaced by a single space might become significant when comments are replaced by a single space might become significant when comments are
retained. Also, comments appearing at the start of what would be a retained. Also, comments appearing at the start of what would be a
...@@ -2925,7 +2991,6 @@ source line, since the first token on the line is no longer a @samp{#}. ...@@ -2925,7 +2991,6 @@ source line, since the first token on the line is no longer a @samp{#}.
@item -traditional @item -traditional
@findex -traditional @findex -traditional
Try to imitate the behavior of old-fashioned C, as opposed to ISO C@. Try to imitate the behavior of old-fashioned C, as opposed to ISO C@.
Note: support for this option is currently fairly broken.
@itemize @bullet @itemize @bullet
@item @item
...@@ -2966,8 +3031,9 @@ together with the text after the macro call, to produce a single token. ...@@ -2966,8 +3031,9 @@ together with the text after the macro call, to produce a single token.
(This is impossible in ISO C@.) (This is impossible in ISO C@.)
@item @item
Traditionally, @samp{\} inside a macro argument suppresses the syntactic None of the GNU extensions to the preprocessor are available in
significance of the following character. @samp{-traditional} mode.
@end itemize @end itemize
@cindex Fortran @cindex Fortran
...@@ -3010,21 +3076,44 @@ place of @code{cpp}. ...@@ -3010,21 +3076,44 @@ place of @code{cpp}.
Process ISO standard trigraph sequences. These are three-character Process ISO standard trigraph sequences. These are three-character
sequences, all starting with @samp{??}, that are defined by ISO C to sequences, all starting with @samp{??}, that are defined by ISO C to
stand for single characters. For example, @samp{??/} stands for stand for single characters. For example, @samp{??/} stands for
@samp{\}, so @samp{'??/n'} is a character constant for a newline. @samp{\}, so @samp{'??/n'} is a character constant for a newline. By
Strictly speaking, the GNU C preprocessor does not conform to ISO default, GCC ignores trigraphs, but in standard-conforming modes it
Standard C unless @samp{-trigraphs} is used, but if you ever notice the converts them. See the @samp{-std} option.
difference it will be with relief.
The nine trigraph sequences are The nine trigraph sequences are
@samp{??(} -> @samp{[}, @table @samp
@samp{??)} -> @samp{]}, @item ??(
@samp{??<} -> @samp{@{}, -> @samp{[}
@samp{??>} -> @samp{@}},
@samp{??=} -> @samp{#}, @item ??)
@samp{??/} -> @samp{\}, -> @samp{]}
@samp{??'} -> @samp{^},
@samp{??!} -> @samp{|}, @item ??<
@samp{??-} -> @samp{~} -> @samp{@{}
@item ??>
-> @samp{@}}
@item ??=
-> @samp{#}
@item ??/
-> @samp{\}
@item ??'
-> @samp{^}
@item ??!
-> @samp{|}
@item ??-
-> @samp{~}
@end table
Trigraph support is not popular, so many compilers do not implement it
properly. Portable code should not rely on trigraphs being either
converted or ignored.
@item -pedantic @item -pedantic
@findex -pedantic @findex -pedantic
...@@ -3038,19 +3127,15 @@ warnings. ...@@ -3038,19 +3127,15 @@ warnings.
@item -Wcomment @item -Wcomment
@findex -Wcomment @findex -Wcomment
@ignore
@c "Not worth documenting" both singular and plural forms of this
@c option, per RMS. Also unclear which is better; hence may need to
@c switch this at some future date. pesch@cygnus.com, 2jan92.
@itemx -Wcomments @itemx -Wcomments
(Both forms have the same effect). (Both forms have the same effect).
@end ignore
Warn whenever a comment-start sequence @samp{/*} appears in a @samp{/*} Warn whenever a comment-start sequence @samp{/*} appears in a @samp{/*}
comment, or whenever a backslash-newline appears in a @samp{//} comment. comment, or whenever a backslash-newline appears in a @samp{//} comment.
@item -Wtrigraphs @item -Wtrigraphs
@findex -Wtrigraphs @findex -Wtrigraphs
Warn if any trigraphs are encountered. Warn if any trigraphs are encountered. This option used to take effect
only if @samp{-trigraphs} was also specified, but now works independently.
@item -Wwhite-space @item -Wwhite-space
@findex -Wwhite-space @findex -Wwhite-space
...@@ -3181,6 +3266,10 @@ predefined macros, and it outputs @emph{both} the @samp{#define} ...@@ -3181,6 +3266,10 @@ predefined macros, and it outputs @emph{both} the @samp{#define}
directives and the result of preprocessing. Both kinds of output go to directives and the result of preprocessing. Both kinds of output go to
the standard output file. the standard output file.
@item -dN
@findex -dN
Like @samp{-dD}, but emit only the macro names, not their expansions.
@item -dI @item -dI
@findex -dI @findex -dI
Output @samp{#include} directives in addition to the result of Output @samp{#include} directives in addition to the result of
...@@ -3327,20 +3416,9 @@ The 1990 C standard plus GNU extensions. This is the default. ...@@ -3327,20 +3416,9 @@ The 1990 C standard plus GNU extensions. This is the default.
The 1999 C standard plus GNU extensions. The 1999 C standard plus GNU extensions.
@end table @end table
@item -Wp,-lint
@findex -lint
Look for commands to the program checker @code{lint} embedded in
comments, and emit them preceded by @samp{#pragma lint}. For example,
the comment @samp{/* NOTREACHED */} becomes @samp{#pragma lint
NOTREACHED}.
Because of the clash with @samp{-l}, you must use the awkward syntax
above. In a future release, this option will be replaced by
@samp{-flint} or @samp{-Wlint}; we are not sure which yet.
@item -ftabstop=NUMBER @item -ftabstop=NUMBER
@findex -ftabstop @findex -ftabstop
Indicates the distance between tabstops. This helps the preprocessor Set the distance between tabstops. This helps the preprocessor
report correct column numbers in warnings or errors, even if tabs appear report correct column numbers in warnings or errors, even if tabs appear
on the line. Values less than 1 or greater than 100 are ignored. The on the line. Values less than 1 or greater than 100 are ignored. The
default is 8. default is 8.
......
...@@ -193,7 +193,7 @@ parse_number (pfile, tok) ...@@ -193,7 +193,7 @@ parse_number (pfile, tok)
{ {
/* Check for a floating point constant. Note that float constants /* Check for a floating point constant. Note that float constants
with an exponent or suffix but no decimal point are technically with an exponent or suffix but no decimal point are technically
illegal (C99 6.4.4.2) but accepted elsewhere. */ invalid (C99 6.4.4.2) but accepted elsewhere. */
if ((c == '.' || c == 'F' || c == 'f') if ((c == '.' || c == 'F' || c == 'f')
|| (base == 10 && (c == 'E' || c == 'e') || (base == 10 && (c == 'E' || c == 'e')
&& p+1 < end && (p[1] == '+' || p[1] == '-')) && p+1 < end && (p[1] == '+' || p[1] == '-'))
......
...@@ -785,7 +785,7 @@ cpp_start_read (pfile, print, fname) ...@@ -785,7 +785,7 @@ cpp_start_read (pfile, print, fname)
if (CPP_OPTION (pfile, cplusplus)) if (CPP_OPTION (pfile, cplusplus))
CPP_OPTION (pfile, warn_traditional) = 0; CPP_OPTION (pfile, warn_traditional) = 0;
/* Do not warn about illegal token pasting if -lang-asm. */ /* Do not warn about invalid token pasting if -lang-asm. */
if (CPP_OPTION (pfile, lang_asm)) if (CPP_OPTION (pfile, lang_asm))
CPP_OPTION (pfile, warn_paste) = 0; CPP_OPTION (pfile, warn_paste) = 0;
......
...@@ -201,6 +201,10 @@ TOKEN_LEN (token) ...@@ -201,6 +201,10 @@ TOKEN_LEN (token)
#define IS_ARG_CONTEXT(c) ((c)->flags & CONTEXT_ARG) #define IS_ARG_CONTEXT(c) ((c)->flags & CONTEXT_ARG)
#define CURRENT_CONTEXT(pfile) ((pfile)->contexts + (pfile)->cur_context) #define CURRENT_CONTEXT(pfile) ((pfile)->contexts + (pfile)->cur_context)
#define ON_REST_ARG(c) \
(((c)->flags & VAR_ARGS) \
&& (c)->u.list->tokens[(c)->posn].val.aux \
== (unsigned int) ((c)->u.list->paramc - 1))
#define ASSIGN_FLAGS_AND_POS(d, s) \ #define ASSIGN_FLAGS_AND_POS(d, s) \
do {(d)->flags = (s)->flags & (PREV_WHITE | BOL | PASTE_LEFT); \ do {(d)->flags = (s)->flags & (PREV_WHITE | BOL | PASTE_LEFT); \
...@@ -990,7 +994,7 @@ parse_name (pfile, tok, cur, rlimit) ...@@ -990,7 +994,7 @@ parse_name (pfile, tok, cur, rlimit)
{ {
if (! is_idchar (*cur)) if (! is_idchar (*cur))
break; break;
/* $ is not a legal identifier character in the standard, but is /* $ is not a identifier character in the standard, but is
commonly accepted as an extension. Don't warn about it in commonly accepted as an extension. Don't warn about it in
skipped conditional blocks. */ skipped conditional blocks. */
if (*cur == '$' && CPP_PEDANTIC (pfile) && ! pfile->skipping) if (*cur == '$' && CPP_PEDANTIC (pfile) && ! pfile->skipping)
...@@ -2732,10 +2736,11 @@ maybe_paste_with_next (pfile, token) ...@@ -2732,10 +2736,11 @@ maybe_paste_with_next (pfile, token)
pasted = duplicate_token (pfile, second); pasted = duplicate_token (pfile, second);
else if (second->type == CPP_PLACEMARKER) else if (second->type == CPP_PLACEMARKER)
{ {
/* GCC has special extended semantics for a ## b where b is /* GCC has special extended semantics for , ## b where b is
a varargs parameter: a disappears if b was given no actual a varargs parameter: the comma disappears if b was given
arguments (not merely if b is an empty argument). */ no actual arguments (not merely if b is an empty
if (second->flags & VOID_REST) argument). */
if (token->type == CPP_COMMA && second->flags & VOID_REST)
pasted = duplicate_token (pfile, second); pasted = duplicate_token (pfile, second);
else else
pasted = duplicate_token (pfile, token); pasted = duplicate_token (pfile, token);
...@@ -2748,8 +2753,19 @@ maybe_paste_with_next (pfile, token) ...@@ -2748,8 +2753,19 @@ maybe_paste_with_next (pfile, token)
if (type == CPP_EOF) if (type == CPP_EOF)
{ {
if (CPP_OPTION (pfile, warn_paste)) if (CPP_OPTION (pfile, warn_paste))
cpp_warning (pfile, {
/* Do not complain about , ## <whatever> if
<whatever> came from a variable argument, because
the author probably intended the ## to trigger
the special extended semantics (see above). */
if (token->type == CPP_COMMA
&& IS_ARG_CONTEXT (CURRENT_CONTEXT (pfile))
&& ON_REST_ARG (CURRENT_CONTEXT (pfile) - 1))
/* no warning */;
else
cpp_warning (pfile,
"pasting would not give a valid preprocessing token"); "pasting would not give a valid preprocessing token");
}
_cpp_push_token (pfile, second); _cpp_push_token (pfile, second);
return token; return token;
} }
...@@ -3287,7 +3303,7 @@ lex_next (pfile, clear) ...@@ -3287,7 +3303,7 @@ lex_next (pfile, clear)
/* Pops a context off the context stack. If we're at the bottom, lexes /* Pops a context off the context stack. If we're at the bottom, lexes
the next logical line. Returns EOF if we're at the end of the the next logical line. Returns EOF if we're at the end of the
argument list to the # operator, or if it is illegal to "overflow" argument list to the # operator, or we should not "overflow"
into the rest of the file (e.g. 6.10.3.1.1). */ into the rest of the file (e.g. 6.10.3.1.1). */
static int static int
pop_context (pfile) pop_context (pfile)
......
...@@ -433,7 +433,7 @@ read_line_number (pfile, num) ...@@ -433,7 +433,7 @@ read_line_number (pfile, num)
/* Another subroutine of do_line. Convert a number in STR, of length /* Another subroutine of do_line. Convert a number in STR, of length
LEN, to binary; store it in NUMP, and return 0 if the number was LEN, to binary; store it in NUMP, and return 0 if the number was
legal, 1 if not. Temporary, hopefully. */ well-formed, 1 if not. Temporary, hopefully. */
static int static int
strtoul_for_line (str, len, nump) strtoul_for_line (str, len, nump)
const U_CHAR *str; const U_CHAR *str;
......
...@@ -127,7 +127,7 @@ count_params (pfile, info) ...@@ -127,7 +127,7 @@ count_params (pfile, info)
{ {
default: default:
cpp_error_with_line (pfile, token->line, token->col, cpp_error_with_line (pfile, token->line, token->col,
"illegal token in macro parameter list"); "token may not appear in macro parameter list");
return; return;
case CPP_EOF: case CPP_EOF:
...@@ -462,7 +462,7 @@ save_expansion (pfile, info) ...@@ -462,7 +462,7 @@ save_expansion (pfile, info)
else else
dest->flags = token->flags; /* Particularly PREV_WHITE. */ dest->flags = token->flags; /* Particularly PREV_WHITE. */
/* Turn off PREV_WHITE if we immediately follow a paste. /* Turn off PREV_WHITE if we immediately follow a paste.
That way, even if the paste turns out to be illegal, there That way, even if the paste turns out to be invalid, there
will be no space between the two tokens in the output. */ will be no space between the two tokens in the output. */
if (token[-1].type == CPP_PASTE) if (token[-1].type == CPP_PASTE)
dest->flags &= ~PREV_WHITE; dest->flags &= ~PREV_WHITE;
......
...@@ -145,11 +145,14 @@ cb_define (pfile, hash) ...@@ -145,11 +145,14 @@ cb_define (pfile, hash)
cpp_reader *pfile; cpp_reader *pfile;
cpp_hashnode *hash; cpp_hashnode *hash;
{ {
cpp_printf (pfile, &parse_out, "#define %s", hash->name); if (pfile->done_initializing)
if (CPP_OPTION (pfile, debug_output) {
|| CPP_OPTION (pfile, dump_macros) == dump_definitions) cpp_printf (pfile, &parse_out, "#define %s", hash->name);
cpp_dump_definition (pfile, parse_out.outf, hash); if (CPP_OPTION (pfile, debug_output)
putc ('\n', parse_out.outf); || CPP_OPTION (pfile, dump_macros) == dump_definitions)
cpp_dump_definition (pfile, parse_out.outf, hash);
putc ('\n', parse_out.outf);
}
} }
static void static void
...@@ -157,7 +160,8 @@ cb_undef (pfile, hash) ...@@ -157,7 +160,8 @@ cb_undef (pfile, hash)
cpp_reader *pfile; cpp_reader *pfile;
cpp_hashnode *hash; cpp_hashnode *hash;
{ {
cpp_printf (pfile, &parse_out, "#undef %s\n", hash->name); if (pfile->done_initializing)
cpp_printf (pfile, &parse_out, "#undef %s\n", hash->name);
} }
static void static void
......
...@@ -125,7 +125,7 @@ lang_specific_driver (in_argc, in_argv, in_added_libraries) ...@@ -125,7 +125,7 @@ lang_specific_driver (in_argc, in_argv, in_added_libraries)
need_E = 0; need_E = 0;
else if (argv[i][1] == 'S' || argv[i][1] == 'c') else if (argv[i][1] == 'S' || argv[i][1] == 'c')
{ {
fatal ("\"%s\" is not a legal option to the preprocessor", fatal ("\"%s\" is not a valid option to the preprocessor",
argv[i]); argv[i]);
return; return;
} }
......
2000-08-02 Zack Weinberg <zack@wolery.cumb.org>
* gcc.dg/cpp/macsyntx.c: Fix error regexp.
Mon Jul 31 21:14:49 2000 Jeffrey A Law (law@cygnus.com) Mon Jul 31 21:14:49 2000 Jeffrey A Law (law@cygnus.com)
* gcc-c-torture/execute/20000731-2.c: New test. * gcc-c-torture/execute/20000731-2.c: New test.
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#define foo(, X) /* { dg-error "parameter name" } */ #define foo(, X) /* { dg-error "parameter name" } */
#define foo(X, X) /* { dg-error "duplicate" } */ #define foo(X, X) /* { dg-error "duplicate" } */
#define foo(X Y) /* { dg-error "comma" } */ #define foo(X Y) /* { dg-error "comma" } */
#define foo(() /* { dg-error "illegal token" } */ #define foo(() /* { dg-error "token may not appear" } */
#define foo(..., X) /* { dg-error "missing" } */ #define foo(..., X) /* { dg-error "missing" } */
#define foo \ #define foo \
__VA_ARGS__ /* { dg-warning "__VA_ARGS__" } */ __VA_ARGS__ /* { dg-warning "__VA_ARGS__" } */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment