- 论坛徽章:
- 20
|
本帖最后由 nswcfd 于 2016-09-13 19:06 编辑
It is often useful to merge two tokens into one while expanding macros.
This is called "token pasting" or "token concatenation". The `##'
preprocessing operator performs token pasting. When a macro is
expanded, the two tokens on either side of each `##' operator are
combined into a single token, which then replaces the `##' and the two
original tokens in the macro expansion. Usually both will be
identifiers, or one will be an identifier and the other a preprocessing
number. When pasted, they make a longer identifier. This isn't the
only valid case. It is also possible to concatenate two numbers (or a
number and a name, such as `1.5' and `e3') into a number. Also,
multi-character operators such as `+=' can be formed by token pasting.
However, two tokens that don't together form a valid token cannot be
pasted together. For example, you cannot concatenate `x' with `+' in
either order. If you try, the preprocessor issues a warning and emits
the two tokens. Whether it puts white space between the tokens is
undefined. It is common to find unnecessary uses of `##' in complex
macros. If you get this warning, it is likely that you can simply
remove the `##'.
----------------------------------------------
Preprocessing tokens fall into five broad classes: identifiers,
preprocessing numbers, string literals, punctuators, and other. An
"identifier" is the same as an identifier in C: any sequence of
letters, digits, or underscores, which begins with a letter or
underscore. Keywords of C have no significance to the preprocessor;
they are ordinary identifiers. You can define a macro whose name is a
keyword, for instance. The only identifier which can be considered a
preprocessing keyword is `defined'. *Note Defined::.
|
|