C-Preprocessor Requirements for MIDL

This page applies only to developers who have specific reasons to replace the Microsoft C/C++ preprocessor as the preprocessor used by MIDL, or to developers who must specify customized preprocessor switches. The MIDL switches /cpp_cmd, /cpp_opt, and /no_cpp are used to override the default behavior of the compiler. There is typically no reason to replace the Microsoft C/C++ preprocessor, nor to specify customized preprocessor switches.

The MIDL compiler uses a C preprocessor during initial processing of the IDL file. The build environment used when compiling the IDL files is associated with a default C/C++ preprocessor. If a different preprocessor is to be used, the MIDL compiler switch /cpp_cmd enables an override of the default C/C++-preprocessor name:

midl /cpp_cmd preprocessor_name filename

preprocessor_name

Specifies the name of the preprocessor to be used by MIDL. May be specified with a path to the binary. The .exe extension is optional.

filename

Specifies the name of the IDL file.

  • The MIDL compiler expects any preprocessor to observe the following conventions:
  • The input file is specified as the last argument on the command line.
  • The preprocessor must redirect output to the standard output device, stdout.
  • In the output stream of the preprocessor, the #line directives are present to enable better diagnostic messages.
  • The line directives are the only preprocessor directives in the output stream.

MIDL assumes that the spawned preprocessor has removed all preprocessor directives from the input stream of the compiler, with the exception of the occurrences of the line directive necessary for pinpointing source location in compiler messages. When indicating a preprocessor different from the Microsoft C/C++ preprocessor, or when specifying preprocessor options with the /cpp_opt switch, specifying an appropriate preprocessor option that puts the line directives in the input stream of the compiler is required. For example, for the Microsoft C/C++ preprocessor the /E option would have to be used:

midl /cpp_cmd cl.exe /cpp_opt "/E" file.idl

The #line directive is accepted by MIDL in one of the following forms:

#line digit-sequence "filename" new-line
 
# digit-sequence "filename" new-line

For a complete description of the line directive and other preprocessor directives, see the documentation for the C-compiler being used.

MIDL accepts only the line preprocessor directive. Therefore, if the /no_cpp switch is used, the input file must not have other preprocessor directives, or the input file must have been processed prior to invoking MIDL.

For more information, see Dealing with #defines in IDL Files.