Reputation: 2492
The #define creates a macro, which is the association of an identifier or parameterized identifier with a token string. After the macro is defined, the compiler can substitute the token string for each occurrence of the identifier in the source file.
https://learn.microsoft.com/en-ca/cpp/preprocessor/hash-define-directive-c-cpp?view=vs-2017
Surprisingly, the question has not been directly asked, rather asking about tokenization
, tokenizer
, tokening
etc. Even searching on DuckDuckGo, the closest question was on quora asking,
And it is not obvious to me whether string token
and token string
would be synonymous. So just to be clear:
What is a token string in c++?
Upvotes: 3
Views: 1367
Reputation: 181027
In this case the token string is the macro body. In
#defined MAKE_MY_FUNC(x) void x(int bar)
The void x(int foo)
part would be considered the token string and when you use MAKE_MY_FUNC
like
MAKE_MY_FUNC(foo){ std::cout << bar; }
then the token string would be subsituted in and the code would be transformed into
void foo(int foo){ std::cout << bar; }
Your article gives you what they call the token-string in the second paragraph
The token-string argument consists of a series of tokens, such as keywords, constants, or complete statements. One or more white-space characters must separate token-string from identifier. This white space is not considered part of the substituted text, nor is any white space that follows the last token of the text.
Upvotes: 4