Commit 95bbcf58 by Sandra Loosemore Committed by Sandra Loosemore

cpp.texi: Replace "stringify"/"stringification" with C standard terminology...

2017-02-11  Sandra Loosemore  <sandra@codesourcery.com>

	gcc/
	* doc/cpp.texi: Replace "stringify"/"stringification" with C 
	standard terminology "stringize"/"stringizing" throughout.
	* doc/cppinternals.texi: Likewise.

From-SVN: r245371
parent 7b65f477
2017-02-11 Sandra Loosemore <sandra@codesourcery.com> 2017-02-11 Sandra Loosemore <sandra@codesourcery.com>
* doc/cpp.texi: Replace "stringify"/"stringification" with C
standard terminology "stringize"/"stringizing" throughout.
* doc/cppinternals.texi: Likewise.
2017-02-11 Sandra Loosemore <sandra@codesourcery.com>
* doc/extend.texi: Fix some spelling mistakes and typos. * doc/extend.texi: Fix some spelling mistakes and typos.
* doc/invoke.texi: Likewise. * doc/invoke.texi: Likewise.
......
...@@ -119,7 +119,7 @@ Macros ...@@ -119,7 +119,7 @@ Macros
* Object-like Macros:: * Object-like Macros::
* Function-like Macros:: * Function-like Macros::
* Macro Arguments:: * Macro Arguments::
* Stringification:: * Stringizing::
* Concatenation:: * Concatenation::
* Variadic Macros:: * Variadic Macros::
* Predefined Macros:: * Predefined Macros::
...@@ -1155,7 +1155,7 @@ macros when you are compiling C++. ...@@ -1155,7 +1155,7 @@ macros when you are compiling C++.
* Object-like Macros:: * Object-like Macros::
* Function-like Macros:: * Function-like Macros::
* Macro Arguments:: * Macro Arguments::
* Stringification:: * Stringizing::
* Concatenation:: * Concatenation::
* Variadic Macros:: * Variadic Macros::
* Predefined Macros:: * Predefined Macros::
...@@ -1453,9 +1453,9 @@ their corresponding actual arguments. ...@@ -1453,9 +1453,9 @@ their corresponding actual arguments.
foo(bar) @expansion{} bar, "x" foo(bar) @expansion{} bar, "x"
@end smallexample @end smallexample
@node Stringification @node Stringizing
@section Stringification @section Stringizing
@cindex stringification @cindex stringizing
@cindex @samp{#} operator @cindex @samp{#} 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
...@@ -1464,16 +1464,16 @@ can use the @samp{#} preprocessing operator instead. When a macro ...@@ -1464,16 +1464,16 @@ can use the @samp{#} preprocessing operator instead. When a macro
parameter is used with a leading @samp{#}, the preprocessor replaces it parameter is used with a leading @samp{#}, the preprocessor replaces it
with the literal text of the actual argument, converted to a string with the literal text of the actual argument, converted to a string
constant. Unlike normal parameter replacement, the argument is not constant. Unlike normal parameter replacement, the argument is not
macro-expanded first. This is called @dfn{stringification}. macro-expanded first. This is called @dfn{stringizing}.
There is no way to combine an argument with surrounding text and There is no way to combine an argument with surrounding text and
stringify it all together. Instead, you can write a series of adjacent stringize it all together. Instead, you can write a series of adjacent
string constants and stringified arguments. The preprocessor will string constants and stringized arguments. The preprocessor
replace the stringified arguments with string constants. The C replaces the stringized arguments with string constants. The C
compiler will then combine all the adjacent string constants into one compiler then combines all the adjacent string constants into one
long string. long string.
Here is an example of a macro definition that uses stringification: Here is an example of a macro definition that uses stringizing:
@smallexample @smallexample
@group @group
...@@ -1489,7 +1489,7 @@ WARN_IF (x == 0); ...@@ -1489,7 +1489,7 @@ WARN_IF (x == 0);
@noindent @noindent
The argument for @code{EXP} is substituted once, as-is, into the The argument for @code{EXP} is substituted once, as-is, into the
@code{if} statement, and once, stringified, into the argument to @code{if} statement, and once, stringized, into the argument to
@code{fprintf}. If @code{x} were a macro, it would be expanded in the @code{fprintf}. If @code{x} were a macro, it would be expanded in the
@code{if} statement, but not in the string. @code{if} statement, but not in the string.
...@@ -1498,24 +1498,24 @@ write @code{WARN_IF (@var{arg});}, which the resemblance of ...@@ -1498,24 +1498,24 @@ write @code{WARN_IF (@var{arg});}, which the resemblance of
@code{WARN_IF} to a function would make C programmers want to do; see @code{WARN_IF} to a function would make C programmers want to do; see
@ref{Swallowing the Semicolon}. @ref{Swallowing the Semicolon}.
Stringification in C involves more than putting double-quote characters Stringizing in C involves more than putting double-quote characters
around the fragment. The preprocessor backslash-escapes the quotes around the fragment. The preprocessor backslash-escapes the quotes
surrounding embedded string constants, and all backslashes within string and surrounding embedded string constants, and all backslashes within string and
character constants, in order to get a valid C string constant with the character constants, in order to get a valid C string constant with the
proper contents. Thus, stringifying @code{@w{p = "foo\n";}} results in proper contents. Thus, stringizing @code{@w{p = "foo\n";}} results in
@t{@w{"p = \"foo\\n\";"}}. However, backslashes that are not inside string @t{@w{"p = \"foo\\n\";"}}. However, backslashes that are not inside string
or character constants are not duplicated: @samp{\n} by itself or character constants are not duplicated: @samp{\n} by itself
stringifies to @t{"\n"}. stringizes to @t{"\n"}.
All leading and trailing whitespace in text being stringified is All leading and trailing whitespace in text being stringized is
ignored. Any sequence of whitespace in the middle of the text is ignored. Any sequence of whitespace in the middle of the text is
converted to a single space in the stringified result. Comments are converted to a single space in the stringized result. Comments are
replaced by whitespace long before stringification happens, so they replaced by whitespace long before stringizing happens, so they
never appear in stringified text. never appear in stringized text.
There is no way to convert a macro argument into a character constant. There is no way to convert a macro argument into a character constant.
If you want to stringify the result of expansion of a macro argument, If you want to stringize the result of expansion of a macro argument,
you have to use two levels of macros. you have to use two levels of macros.
@smallexample @smallexample
...@@ -1530,7 +1530,7 @@ xstr (foo) ...@@ -1530,7 +1530,7 @@ xstr (foo)
@expansion{} "4" @expansion{} "4"
@end smallexample @end smallexample
@code{s} is stringified when it is used in @code{str}, so it is not @code{s} is stringized when it is used in @code{str}, so it is not
macro-expanded first. But @code{s} is an ordinary argument to macro-expanded first. But @code{s} is an ordinary argument to
@code{xstr}, so it is completely macro-expanded before @code{xstr} @code{xstr}, so it is completely macro-expanded before @code{xstr}
itself is expanded (@pxref{Argument Prescan}). Therefore, by the time itself is expanded (@pxref{Argument Prescan}). Therefore, by the time
...@@ -1569,7 +1569,7 @@ but you could just as well write them as one token in the first place. ...@@ -1569,7 +1569,7 @@ but you could just as well write them as one token in the first place.
Token pasting is most useful when one or both of the tokens comes from a Token pasting is most useful when one or both of the tokens comes from a
macro argument. If either of the tokens next to an @samp{##} is a macro argument. If either of the tokens next to an @samp{##} is a
parameter name, it is replaced by its actual argument before @samp{##} parameter name, it is replaced by its actual argument before @samp{##}
executes. As with stringification, the actual argument is not executes. As with stringizing, the actual argument is not
macro-expanded first. If the argument is empty, that @samp{##} has no macro-expanded first. If the argument is empty, that @samp{##} has no
effect. effect.
...@@ -1607,7 +1607,7 @@ struct command commands[] = ...@@ -1607,7 +1607,7 @@ struct command commands[] =
It would be cleaner not to have to give each command name twice, once in It would be cleaner not to have to give each command name twice, once in
the string constant and once in the function name. A macro which takes the the string constant and once in the function name. A macro which takes the
name of a command as an argument can make this unnecessary. The string name of a command as an argument can make this unnecessary. The string
constant can be created with stringification, and the function name by constant can be created with stringizing, and the function name by
concatenating the argument with @samp{_command}. Here is how it is done: concatenating the argument with @samp{_command}. Here is how it is done:
@smallexample @smallexample
...@@ -1649,7 +1649,7 @@ eprintf ("%s:%d: ", input_file, lineno) ...@@ -1649,7 +1649,7 @@ eprintf ("%s:%d: ", input_file, lineno)
The variable argument is completely macro-expanded before it is inserted The variable argument is completely macro-expanded before it is inserted
into the macro expansion, just like an ordinary argument. You may use into the macro expansion, just like an ordinary argument. You may use
the @samp{#} and @samp{##} operators to stringify the variable argument the @samp{#} and @samp{##} operators to stringize the variable argument
or to paste its leading or trailing token with another token. (But see or to paste its leading or trailing token with another token. (But see
below for an important special case for @samp{##}.) below for an important special case for @samp{##}.)
...@@ -2912,7 +2912,7 @@ macro, but not when it indirectly appears in its own definition. ...@@ -2912,7 +2912,7 @@ macro, but not when it indirectly appears in its own definition.
@cindex prescan of macro arguments @cindex prescan of macro arguments
Macro arguments are completely macro-expanded before they are Macro arguments are completely macro-expanded before they are
substituted into a macro body, unless they are stringified or pasted substituted into a macro body, unless they are stringized or pasted
with other tokens. After substitution, the entire macro body, including with other tokens. After substitution, the entire macro body, including
the substituted arguments, is scanned again for macros to be expanded. the substituted arguments, is scanned again for macros to be expanded.
The result is that the arguments are scanned @emph{twice} to expand The result is that the arguments are scanned @emph{twice} to expand
...@@ -2952,12 +2952,12 @@ appear during the main scan as an indirect self-reference and would not ...@@ -2952,12 +2952,12 @@ appear during the main scan as an indirect self-reference and would not
be expanded. be expanded.
@item @item
Macros that call other macros that stringify or concatenate. Macros that call other macros that stringize or concatenate.
If an argument is stringified or concatenated, the prescan does not If an argument is stringized or concatenated, the prescan does not
occur. If you @emph{want} to expand a macro, then stringify or occur. If you @emph{want} to expand a macro, then stringize or
concatenate its expansion, you can do that by causing one macro to call concatenate its expansion, you can do that by causing one macro to call
another macro that does the stringification or concatenation. For another macro that does the stringizing or concatenation. For
instance, if you have instance, if you have
@smallexample @smallexample
...@@ -3830,7 +3830,7 @@ implementation removes comments even before saving the macro ...@@ -3830,7 +3830,7 @@ implementation removes comments even before saving the macro
replacement text, but it careful to do it in such a way that the replacement text, but it careful to do it in such a way that the
observed effect is identical even in the function-like macro case.) observed effect is identical even in the function-like macro case.)
The ISO stringification operator @samp{#} and token paste operator The ISO stringizing operator @samp{#} and token paste operator
@samp{##} have no special meaning. As explained later, an effect @samp{##} have no special meaning. As explained later, an effect
similar to these operators can be obtained in a different way. Macro similar to these operators can be obtained in a different way. Macro
names that are embedded in quotes, either from the main file or after names that are embedded in quotes, either from the main file or after
......
...@@ -203,7 +203,7 @@ error about an unterminated macro argument list. ...@@ -203,7 +203,7 @@ error about an unterminated macro argument list.
The C standard also specifies that a new line in the middle of the The C standard also specifies that a new line in the middle of the
arguments to a macro is treated as whitespace. This white space is arguments to a macro is treated as whitespace. This white space is
important in case the macro argument is stringified. The state variable important in case the macro argument is stringized. The state variable
@code{parsing_args} is nonzero when the preprocessor is collecting the @code{parsing_args} is nonzero when the preprocessor is collecting the
arguments to a macro call. It is set to 1 when looking for the opening arguments to a macro call. It is set to 1 when looking for the opening
parenthesis to a function-like macro, and 2 when collecting the actual parenthesis to a function-like macro, and 2 when collecting the actual
...@@ -374,7 +374,7 @@ the pointers to the tokens of its expansion that are returned will always ...@@ -374,7 +374,7 @@ the pointers to the tokens of its expansion that are returned will always
remain valid. However, macros are a little trickier than that, since remain valid. However, macros are a little trickier than that, since
they give rise to three sources of fresh tokens. They are the built-in they give rise to three sources of fresh tokens. They are the built-in
macros like @code{__LINE__}, and the @samp{#} and @samp{##} operators macros like @code{__LINE__}, and the @samp{#} and @samp{##} operators
for stringification and token pasting. I handled this by allocating for stringizing and token pasting. I handled this by allocating
space for these tokens from the lexer's token run chain. This means space for these tokens from the lexer's token run chain. This means
they automatically receive the same lifetime guarantees as lexed tokens, they automatically receive the same lifetime guarantees as lexed tokens,
and we don't need to concern ourselves with freeing them. and we don't need to concern ourselves with freeing them.
...@@ -478,7 +478,7 @@ ways. ...@@ -478,7 +478,7 @@ ways.
I strongly recommend you have a good grasp of how the C and C++ I strongly recommend you have a good grasp of how the C and C++
standards require macros to be expanded before diving into this standards require macros to be expanded before diving into this
section, let alone the code!. If you don't have a clear mental section, let alone the code!. If you don't have a clear mental
picture of how things like nested macro expansion, stringification and picture of how things like nested macro expansion, stringizing and
token pasting are supposed to work, damage to your sanity can quickly token pasting are supposed to work, damage to your sanity can quickly
result. result.
...@@ -744,7 +744,7 @@ We would then have it take its spacing from the first of these, which ...@@ -744,7 +744,7 @@ We would then have it take its spacing from the first of these, which
carries source token @samp{foo} with no leading space. carries source token @samp{foo} with no leading space.
It is vital that cpplib get spacing correct in these examples since any It is vital that cpplib get spacing correct in these examples since any
of these macro expansions could be stringified, where spacing matters. of these macro expansions could be stringized, where spacing matters.
So, this demonstrates that not just entering macro and argument So, this demonstrates that not just entering macro and argument
expansions, but leaving them requires special handling too. I made expansions, but leaving them requires special handling too. I made
......
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