CL /D

Syntax

/Dname[=[value]]

/Dname[#[value]]

/D=[value]

/D#[value]

The required argument consists of whatever follows immediately within the same command-line token, else is the whole of the next command-line token.

Failure to provide an argument is an error (D2004). There is no formal constraint on the length of the argument.

The argument is parsed into a name and value. The name extends up to but not including the first # or = sign. Should anything remain in the argument, then in general, it becomes the value. For ease of reference, support for the # sign as the separator is henceforth taken as understood. Indeed, the first # sign in the argument actually is replaced by an = sign as far as concerns all subsequent interpretation of the argument by CL or communication to any compiler module. The coding has a side-effect, possibly by oversight: if the separator (as given) between name and value is an = sign, then the first # sign in value (as interpreted) is changed to an = sign.

Relations

A /D option with a name overrides earlier instances of /D with the same name. A /D option with no name overrides earlier instances of /D with no name. In neither case is there a warning.

The /D option passes to the front-end C and C++ compilers (C1 and C1XX).

Defaults

The following /D options are set by default, being hard-coded in CL as initial options:

Behaviour

The /D option directs the compiler to define name as a preprocessor macro of the sort that has no argument list (as opposed to an empty argument list). The given value, after discarding any trailing white space in excess of one character, becomes the macro’s expansion. If the /D option provides no value but ends with an = sign, then the macro is defined as having no expansion. With no = sign, the macro is defined as expanding to 1.

The syntax in which /D provides no name is not invalid. The compiler actually does define a nameless macro, though this is surely redundant, at least in practice, unless there comes to light some way to access such a macro from source code. Indeed, the compiler imposes no formal syntax on the name. In particular, name need not be a C/C++ identifier, though there would seem to be no practical value to such a name, since there is again no way to access the resulting macro from source code.

Macro definitions in response to /D options are performed immediately after the compiler defines built-in macros.