I,In the gcc Parameter
-Dmacro is equivalent to # define macro-Dmacro = value in the Code. # define macro value-Umacro is equivalent to # undef macro in the code.
II,Macro definition,
Slash (
"\") Is used to resume rows,
"
#
"Is used to convert a parameter to a string, which is to add double quotation marks to the parameter.
"
##
"Is used to connect the first and second parameters and convert them into a string,
"
# @ "Adds single quotation marks to parameters.
For example
#define Conn(x,y) x##y
#define ToChar(a) #@a
#define ToString(x) #x
int
n = Conn(123,456);
Result n = 123456;
char
* str = Conn(
"asdf"
,
"adf"
)
Result str =
"asdfadf"
;
char
a = ToChar(1);
Result
A =
'1'
;
char
* str = ToString(123132);
Result
Str =
"123132"
;
3. Use the-D macro defined as a string in CodeBlocks. If a Bug exists, for example, when the log macro of G_LOG_DOMAIN of Glib is defined, when-DG_LOG_DOMAIN = "plugin_dispatch" is added to the compilation option, the system prompts plugin_dispatch is undefined. This is obviously because double quotation marks are discarded during macro preprocessing. The solution is to use gmacros. h # define partition (contents) # contentsG_LOG_DOMAIN = G_STRINGIFY_ARG (plugin_dispatch) Build prompt syntax error near unexpected token '(' changed to G_LOG_DOMAIN = "plugin (plugin_dispatch)" build successful