Partager via


/D - Define Constants and Macros

This option defines constants or macros in a source file. The identifier is the name of the constant or macro. It can be a string or as a number. No space separates /D and the identifier. Enclose the string in quotes if it includes spaces.

/Didentifier[<= | # [<{string | number}>] >]

With Microsoft C or C++, you can substitute a number sign (#) for an equal sign (=) when setting the identifier to string | number. From either the MS-DOS command line or from a batch file, you cannot set an environment variable to a string that contains an equal sign. Environment variables, however, accept the number sign.

If you omit both the equal sign and the string or number, the compiler assumes the value of the identifier is defined, and sets its value to one. For example, entering /DSET defines a macro named SET with a value of one. The identifier argument is case-sensitive. For example, the preceding /D option would have no effect on a constant named set that is defined in the source file.

Use the constants created by the compiler and the /D option in combination with either the #if or #ifdef directive to compile source files conditionally.

You can replace a keyword, an identifier, or a numeric constant with no text in a source file. To do so, use the /D option with a keyword, an identifier, or a numeric constant and append an equal sign followed by a space. For example, use the following command to remove all occurrences of RELEASE from Test.c:

CLxxx /DRELEASE= TEST.C

Where CLxxx is the name of the compiler for the target processor family.

Defining macros and constants with the /D option has the same effect as using a #define preprocessor directive at the beginning of your source file. The identifier is defined until either an #undef directive in the source file removes the definition or the compiler reaches the end of the file.

If an identifier defined in a /D option is also defined within the source file, the compiler uses the definition on the command line until it encounters the redefinition of the identifier in the source file.

The following code example calls a function to check the near heap unless the constant RELEASE is defined.

#if !defined(RELEASE)
     __nheapchk();
#endif

See Also

About Microprocessor Compilers | ARM Guide | Hitachi Guide | MIPS Guide

 Last updated on Thursday, April 08, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.