This documentation is archived and is not being maintained.

/D (Preprocessor Definitions)

/Dname[= | # [{string | number}] ]

This option defines a preprocessing symbol for your source file. You can use this symbol with #if or #ifdef to compile source conditionally. The symbol definition remains in effect until a redefinition is encountered in source or the symbol is undefined in source with the #undef.

/D has much the same effect as using the #define preprocessor directive at the beginning of your source file. However, /D strips quotes on the command line while #define retains them.

By default, the value associated with a symbol will be 1. That is, /DTEST is equivalent to /DTEST=1 and will cause the following program to print 1.

// cpp_D_compiler_option.cpp
// compile with: /DTEST
#include <stdio.h>
int main()
   #ifdef TEST
      printf("TEST defined %d\n", TEST);
      printf("TEST not defined\n");


TEST defined 1

Compiling with /Dname= causes the symbol to not have an associated value. So, while the symbol can still be used to conditionally compile code, the symbol will otherwise evaluate to nothing. For example, in the previous sample program, compiling with /DTEST= will cause a compiler error. This behavior is similar to using #define with or without a value.

To set this compiler option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box. For details, see Setting Visual C++ Project Properties.
  2. Click the C/C++ folder.
  3. Click the Preprocessor property page.
  4. Modify the Preprocessor Definitions property.

To set this compiler option programmatically

See PreprocessorDefinitions Property.


The following command defines the symbol DEBUG in TEST.c:


The following command removes all occurrences of the keyword __far in TEST.c:

CL /D__far=  TEST.C

You cannot set the CL environment variable to a string that contains an equal sign. To use /D with the CL environment variable, you must specify a number sign instead of an equal sign:


See Also

Compiler Options | Setting Compiler Options | Undefine Symbols (/U, /u)