Preprocessor operators # and ##
# placed before macro argument turns it into a string. For example, the code:
after the preprocessing stage will turn into
A useful example of using - debug, the ASSERT macro. Example implementation:
If you tell him about the condition, for example, ASSERT(2 * 2 != 4), it will display something like:
and will shut down the program.
## need to peck the macro arguments with the other parts of the macro or to each other. It is used rarely, mostly for code generation. Example from Wikipedia:
After preprocessing becomes:
In the beginning of the line # means actually the beginning of a preprocessor Directive. In the middle of a Directive that refers to it. The fact is that if the macro is inside the quotes, the replacement is not happening. If we need to make makrothumeo in quotation marks, you can write:
will be deployed so
Two ## will produce when you deploy a concatenation of the actual parameters of the macro:
will unfold in
Cm. K&R Chapter 4.11.2
Something like this...
UPD: the Operator ## is used very infrequently, so it can not think...
He is used rarely because not thinking about it. And we are the operators and not the directives. - 05-10-2011 в 08:23:20
We are talking about USING them! Unless someone can describe a statement without giving examples? What a bullshit... UPD: not just to describe and CLEARLY describe! - 05-10-2011 в 20:40:04