Noeud:Defining Constants, Noeud « Next »:Default File Renaming, Noeud « Previous »:C Language Features, Noeud « Up »:Useful GCC Options
The -D
option1 acts like a #define
in the source code, and can be used
to set the value of a symbol on the command line:
-DDEFN
| Define DEFN to have the value 1; use with the preprocessor option
#if .
|
-DDEFN=VAL
| Define DEFN to have the value VAL .
|
-UDEFN
| Undefine any constants with definition DEFN (all -D
options are evaluated before any -U options on the command line).
|
For example, the command:
$ gcc -DDOC_FILE=\"info\" -DUSE_POLL file.c
sets DOC_FILE
to the string "info" (the backslashes are there to
make sure that they're interpreted part of the string). This can be useful for
controlling which file a program opens, for example. The second -D
option defines the USE_POLL
sysmbol to have the value 1, and you use
the #if
directive to see whether USE_POLL
(or any other value
set by -D
) is set.