Defining some macros using # define, making some neat substitutions, and even some macros with parameters, are common in Linux C code, which means it's good and useful.
But it also has some complicated rules and traps to note, and I'll record some of them for reference only.
1, when using "\" To change lines, the second line to shelf write, otherwise there will be more than a space. For example:
#define OW "What is you doi \
Ng? "
The second row of ng? " There is no shelf to write, so when the substitution is made, it will:
What is you doi ng?
The correct definition is:
#define OW "What is you doi\
Ng? "
2. The macro can replace the length of the array, but const-defined constants are not allowed.
#define LIMIT 60
const int lmt=12;
int A[limit]; Effective
int A[LMT]; Invalid
Cause: In C, the size of the non-automatic array should be an integer constant expression, which means that the group size must be
A combination of integral constants (such as 5), enumeration constants, and sizeof expressions, but does not include the value of a const declaration.
The use of macros in C language, a few points to note