Home | Overview | How Do I | Compiler Options
This option defines symbols or constants for your source file.
Command Line | Project Settings | Description |
/Dname[= | # [{string | number}] ] | Preprocessor Definitions | With one exception, defining symbols and constants with this option has the same effect as using a #define preprocessor directive at the beginning of your source file. If you use /D, quotes on the command line will be stripped whereas they are retained in a #define statement. The constant is defined until either an #undef directive in the source file removes the definition, or the compiler reaches the end of the file. |
To find this option in the development environment, click Settings on the Project menu. Then click the C/C++ tab, and click Preprocessor in the Category box.
Note The behavior of the Preprocessor Definitions text box differs from the behavior of the /D command-line option; you cannot use either an equal sign (=) or a number sign (#) to assign a value to symbols typed in the text box.
Use the constants created by the compiler and this option in combination with either the #if or #ifdef directive to compile source files conditionally.
You can redefine a keyword, identifier, or numeric constant that has been defined in a source file. If a constant defined in a /D option is also defined within the source file, CL uses the definition on the command line until it encounters a redefinition in the source file.
You can undefine a previous definition. To do so, use the /D option with a keyword, identifier, or numeric constant, and append an equal sign (=) followed by a space.
You cannot set the CL environment variable to a string that contains an equal sign. To use /D with the CL environment variable, specify a number sign instead of an equal sign:
SET CL "/DTEST#0"
The following command defines the symbol DEBUG in TEST.C:
CL /DDEBUG TEST.C
The following command removes all occurrences of the keyword __far in TEST.C:
CL /D__far= TEST.C
See Also Undefine Symbols (/U, /u)