How To Use the Token Pasting Operator in Microsoft C (51712)
The information in this article applies to:
- Microsoft Visual C++ 1.0
- Microsoft Visual C++ 1.5
- Microsoft Visual C++ 2.0
- Microsoft Visual C++ 4.0
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
This article was previously published under Q51712 SUMMARY
In Microsoft C, the token pasting operator (##) is used to
replace tokens within a preprocessor string. The (##) can be used to
mark off the first portion of the string as a token, the last part of
the string as a token, or the middle of a string as a portion. See the
examples shown below.
The token pasting operator cannot be the first or the last token in a
preprocessor string. The first example below (GLUE) demonstrates the
use of the token pasting operator to concatenate two tokens. There is
a replaceable token in front of the operator and one following the
operator. The token pasting operator effectively divides the string
into the two pieces.
A more complex situation arises when using the token pasting operator
to replace a token embedded within a string (for example,
THIS_IS_A_size_TOKEN, where size could be replaced with either LARGE
or SMALL); the token to be replaced must be surrounded by token
pasting operators (##). This is necessary only when the token to be
replaced is completely embedded in another string (see example 2).
Normally, the space character is used as one of the token markers,
while the (##) marks the other end. Only in this specific case (an
embedded token) is more than one token pasting operator needed.
Modification Type: | Minor | Last Reviewed: | 7/5/2005 |
---|
Keywords: | kbcode kbhowto kbLangC KB51712 |
---|
|