The Meaning of # # # in C++/C macro definition (define)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # define.
#是字符串化的意思, the # that appears in the macro definition is a string that is followed by a parameter;
eg
#define STRCPY__ (DST, SRC) strcpy (DST, #src)
Strcpy__ (BUFF,ABC) equivalent to strcpy__ (buff, "abc")
# #是连接符号, connect the parameters together
#define FUN (ARG) my# #arg
Then Fun (ABC)
Equivalent to MYABC
Let's look at a concrete example.
#include <iostream>
using namespace Std;
#define OUTPUT (a) cout<< #A << ":" << (a) <<endl;
int main () {
int a=1,b=2;
OUTPUT (a);
OUTPUT (b);
OUTPUT (A+B);
return 1; }
# # # # # # # # # # # # # # # # # # # # # # We get this result, we print the value of a, B, it's in accordance with the grammatical rules #include <iostream>
using namespace Std;
#define OUTPUT (a) cout<<a<< ":" << (a) <<endl;
int main ()
{
int a=1,b=2;
OUTPUT (a);
OUTPUT (b);
OUTPUT (A+B);
return 1;
}
C++/C macro Definition (define) # # # meaning Macro stitching