/D (Preprocessor Definitions)

Defines a preprocessing symbol for your source file.

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


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 directive.

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

By default, the value associated with a symbol will be 1. That is, /DTEST is equivalent to /DTEST=1. In the following example, the definition of TEST is shown to print 1.

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

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:


To set this compiler option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box. For details, see How to: Open Project Property Pages.

  2. Click the C/C++ folder.

  3. Click the Preprocessor property page.

  4. Modify the Preprocessor Definitions property.

To set this compiler option programmatically


// cpp_D_compiler_option.cpp
// compile with: /DTEST
#include <stdio.h>

int main( )
    #ifdef TEST
        printf_s("TEST defined %d\n", TEST);
        printf_s("TEST not defined\n");

TEST defined 1

See Also


Compiler Options

Setting Compiler Options

/U, /u (Undefine Symbols)

The #undef Directive

The #define Directive