The meaning of # and ## in #define

Detailed explanation one:

In the define instruction format, # is Stringizing Operator, which means to convert formal parameters into strings, as in the above example: 

#define   paster(n)
printf("token "#n" = %d", token##n)

#n is converted to "n", and the space between it and the preceding and following identifiers will be ignored. 


## is the Token-Pasting Operator. In the define instruction, it can connect two tokens together. 
For example: 
#define link(a,b)  a##b

Then link(abc,def) is abcdef after being precompiled by the compiler. 


Detailed explanation two:

The # in the #define statement is to stringify the parameters, and ## is to connect the two parameters into a whole.
#define FACTORY_REF(name) { #name, Make##name }
#name is to stringify the incoming name, and Make##name is to connect Make and name to make them a whole.

statement

FACTORY_REF(MP3Decoder)
means:
{“MP3Decoder” , MakeMP3Decoder}



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326121243&siteId=291194637