Distinguish "preprocessing operator" from "operator" tout court.

This commit is contained in:
Richard Stallman 2023-12-14 08:15:22 -05:00
parent c65c03ca79
commit b29f2c8bd3
1 changed files with 25 additions and 16 deletions

View File

@ -68,6 +68,13 @@ or warnings.
Except for expansion of predefined macros, all these operations happen Except for expansion of predefined macros, all these operations happen
only if you use preprocessing directives to request them. only if you use preprocessing directives to request them.
@cindex preprocessing operators
Preprocessing does not recognize the operators of the C language
itself, outside of the operand of the @code{#if} directive
(@pxref{if}). However, it supports three @dfn{preprocessing
operators} of its own: @code{#} (@pxref{Stringification}), @code{##}
(@pxref{Concatenation}) and @code{defined} (@pxref{if}).
@node Directives @node Directives
@section Directives @section Directives
@cindex directives @cindex directives
@ -157,7 +164,7 @@ The distinction between lexically valid and invalid floating-point
numbers, for example, doesn't matter at this stage. The use of numbers, for example, doesn't matter at this stage. The use of
preprocessing numbers makes it possible to split an identifier at any preprocessing numbers makes it possible to split an identifier at any
position and get exactly two tokens, and reliably paste them together position and get exactly two tokens, and reliably paste them together
using the @code{##} operator (@pxref{Concatenation}). using the @code{##} preprocessing operator (@pxref{Concatenation}).
@item punctuator @item punctuator
A @dfn{punctuator} is syntactically like an operator. A @dfn{punctuator} is syntactically like an operator.
@ -589,7 +596,7 @@ keywords. This can be useful if you wish to hide a keyword such as
However, the preprocessing operator @code{defined} (@pxref{defined}) However, the preprocessing operator @code{defined} (@pxref{defined})
can never be defined as a macro. can never be defined as a macro.
The operator @code{#} is used in macros for stringification of an The preprocessing operator @code{#} is used in macros for stringification of an
argument (@pxref{Stringification}), and @code{##} is used for argument (@pxref{Stringification}), and @code{##} is used for
concatenation of arguments into larger tokens (@pxref{Concatenation}) concatenation of arguments into larger tokens (@pxref{Concatenation})
@ -938,7 +945,7 @@ foo()def @expansion{} abc def
@node Stringification @node Stringification
@subsection Stringification @subsection Stringification
@cindex stringification @cindex stringification
@cindex @code{#} operator @cindex @code{#} preprocessing operator
Sometimes you may want to convert a macro argument into a string Sometimes you may want to convert a macro argument into a string
constant. Parameters are not replaced inside string constants, but constant. Parameters are not replaced inside string constants, but
@ -1028,7 +1035,7 @@ macro-expanded.
@cindex concatenation @cindex concatenation
@cindex token pasting @cindex token pasting
@cindex token concatenation @cindex token concatenation
@cindex @code{##} operator @cindex @code{##} preprocessing operator
It is often useful to merge two tokens into one while expanding macros. It is often useful to merge two tokens into one while expanding macros.
This is called @dfn{token pasting} or @dfn{token concatenation}. The This is called @dfn{token pasting} or @dfn{token concatenation}. The
@ -1071,7 +1078,7 @@ concatenated.
It is an error to use @code{##} at the beginning or end of a macro It is an error to use @code{##} at the beginning or end of a macro
body. body.
Multiple @code{##} operators are handled left-to-right, so that Multiple @code{##} preprocessing operators are handled left-to-right, so that
@samp{1 ## e ## -2} pastes into @samp{1e-2}. (Right-to-left @samp{1 ## e ## -2} pastes into @samp{1e-2}. (Right-to-left
processing would first generate @samp{e-2}, which is an invalid token.) processing would first generate @samp{e-2}, which is an invalid token.)
When @code{#} and @code{##} are used together, they are all handled When @code{#} and @code{##} are used together, they are all handled
@ -1144,11 +1151,12 @@ eprintf ("%s:%d: ", input_file, lineno)
@expansion{} fprintf (stderr, "%s:%d: ", input_file, lineno) @expansion{} fprintf (stderr, "%s:%d: ", input_file, lineno)
@end example @end example
The variable argument is completely macro-expanded before it is inserted The variable argument is completely macro-expanded before it is
into the macro expansion, just like an ordinary argument. You may use inserted into the macro expansion, just like an ordinary argument.
the @code{#} and @code{##} operators to stringify the variable argument You may use the @code{#} and @code{##} preprocessing operators to
or to paste its leading or trailing token with another token. (But see stringify the variable argument or to paste its leading or trailing
below for an important special case for @code{##}.) token with another token. (But see below for an important special
case for @code{##}.)
@strong{Warning:} don't use the identifier @code{@w{__VA_ARGS__}} @strong{Warning:} don't use the identifier @code{@w{__VA_ARGS__}}
for anything other than this. for anything other than this.
@ -1350,8 +1358,9 @@ The rest of the predefined macros are GNU C extensions.
@item __COUNTER__ @item __COUNTER__
This macro expands to sequential integral values starting from 0. In This macro expands to sequential integral values starting from 0. In
other words, each time the program uses this macro, it generates the other words, each time the program uses this macro, it generates the
next successive integer. This, with the @code{##} operator, provides next successive integer. This, with the @code{##} preprocessing
a convenient means for macros to generate unique identifiers. operator, provides a convenient means for macros to generate unique
identifiers.
@item __GNUC__ @item __GNUC__
@itemx __GNUC_MINOR__ @itemx __GNUC_MINOR__
@ -2042,7 +2051,7 @@ A @dfn{conditional} is a preprocessing directive that controls whether
or not to include a chunk of code in the final token stream that is or not to include a chunk of code in the final token stream that is
compiled. Preprocessing conditionals can test arithmetic expressions, compiled. Preprocessing conditionals can test arithmetic expressions,
or whether a name is defined as a macro, or both together using the or whether a name is defined as a macro, or both together using the
special @code{defined} operator. special @code{defined} preprocessing operator.
A preprocessing conditional in C resembles in some ways an @code{if} A preprocessing conditional in C resembles in some ways an @code{if}
statement in C, but it is important to understand the difference between statement in C, but it is important to understand the difference between
@ -2242,8 +2251,8 @@ Macros. All macros in the expression are expanded before actual
computation of the expression's value begins. computation of the expression's value begins.
@item @item
Uses of the @code{defined} operator, which lets you check whether macros Uses of the @code{defined} preprocessing operator, which lets you
are defined in the middle of an @code{#if}. check whether macros are defined in the middle of an @code{#if}.
@item @item
Identifiers that are not macros, which are all considered to be the Identifiers that are not macros, which are all considered to be the
@ -2276,7 +2285,7 @@ value comes out to be nonzero, the @code{#if} succeeds and the
@subsubsection The @code{defined} test @subsubsection The @code{defined} test
@cindex @code{defined} @cindex @code{defined}
The special operator @code{defined} is used in @code{#if} and The preprocessing operator @code{defined} is used in @code{#if} and
@code{#elif} expressions to test whether a certain name is defined as a @code{#elif} expressions to test whether a certain name is defined as a
macro. @code{defined @var{name}} and @code{defined (@var{name})} are macro. @code{defined @var{name}} and @code{defined (@var{name})} are
both expressions whose value is 1 if @var{name} is defined as a macro at both expressions whose value is 1 if @var{name} is defined as a macro at