I. special string macro [cpp] # defineA (x) T _ # x # defineB (x) # @ x # defineC (x) # x we suppose x = 1, the macro definition above will be interpreted as follows: A (1) ------ & gt; T_1B (1) ------ & gt; & #39; 1 & #39; C (1) ------ & gt 1: special string macros
[Cpp]
# Define A (x) T _ # x
# Define B (x) # @ x
# Define C (x) # x
Assume that x = 1, the macro definition above will be interpreted as follows:
A (1) ------> T_1
B (1) ------> '1'
C (1) ------> "1"
These functions are mainly used in string processing functions and parameter naming. they are not complex, but few are known.
II. shielding useless parameter warnings
[Cpp]
# Define UNUSED_PARAM (p) (void) p)
This is used to block invalid parameters
For example
[Cpp] view plaincopy
Void a (int x1, int x2)
{
// Do nothing
}
A warning is displayed. x1 and x2 are invalid parameters.
However, it doesn't matter if you write it like this.
[Cpp]
Void a (int x1, int x2)
{
UNUSED_PARAM (x1 );
UNUSED_PARAM (x2 );
}
3: I can't think of it. I want to hold a place and wait until I wake up.
I will not write more common macro usage, such as the header file security macro, version definition macro, flexible use indeed get twice the result with half the effort.