Tuesday, 9 August 2016

C++ - STRINGNIFY OPERATION IN MACRO

 
# will convert the argument of the macro function in to string literal.
For example,

#define foo(arg) #arg
std::cout<<foo(helloWorld);

During preprocessing foo(helloWorld) will be expanded as “helloWorld” due to the foo macro function.


## is used to merge two literal in macro function.
For example,

#define foo(arg1,arg2) arg1##arg2
std::cout<<foo(hello,ArrayNotFound);


During preprocessing foo(hello,ArrayNotFound)  will be expanded as “helloArrayNotFound” due to the foo macro function.