Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out cl.exe's built-in macros

Tags:

Does anyone know how could I find out which are cl.exe's builtin/predefined macros? For example for gcc the following command line will list all the compiler's builtin macros

gcc -dM -E - </dev/null 

EDIT: I'm interested in a way similar to gcc's that is "ask the actual compiler".

Thanks

like image 392
celavek Avatar asked Sep 08 '10 07:09

celavek


People also ask

Where is Cl exe stored?

cl.exe is usually located at %VCINSTALLDIR%\bin\ . VCINSTALLDIR environment variable is not set by default, but it is being set when you open Visual Studio's Native Tools Command Prompt.

What compiler is cl exe?

cl.exe is a tool that controls the Microsoft C++ (MSVC) C and C++ compilers and linker. cl.exe can be run only on operating systems that support Microsoft Visual Studio for Windows.


1 Answers

This method does amount to asking the compiler for the list of predefined macros, but it uses undocumented features and provides only a partial list. I include it here for completeness.

The Microsoft C/C++ compiler allows an alternative compiler front-end to be invoked using the /B1 and /Bx command line switches for .c and .cpp files respectively. The command-line interface module CL.exe passes a list of options to the replacement compiler front-end via the MSC_CMD_FLAGS environment variable. This list of options includes -D macro definitions for some of the predefined macros.

The following trivial replacement compiler front-end prints out the list of options passed to it:

/* MyC1.c */  #include <stdio.h> #include <stdlib.h>  int main(void) {     char *p;      if ((p = getenv("MSC_CMD_FLAGS")) != NULL)         printf("MSC_CMD_FLAGS:\n%s\n", p);      if ((p = getenv("MSC_IDE_FLAGS")) != NULL)         printf("MSC_IDE_FLAGS:\n%s\n", p);      return EXIT_FAILURE; } 

Compile this to an executable named, for example, "MyC1.exe", ensure it is visible in the PATH and tell CL.exe to invoke it as the compiler front-end using one of the following:

cl /B1MyC1.exe AnyNameHere.c   cl /BxMyC1.exe AnyNameHere.cpp   

Include other command-line options as required to see which macros are predefined for that set of options.

In the resulting output look for the -D options. An example list is given below. In the actual output the list will be space-separated, with each macro definition preceded by -D, and other options also present.

_MSC_EXTENSIONS   _INTEGRAL_MAX_BITS=64   _MSC_VER=1600   _MSC_FULL_VER=160030319   _MSC_BUILD=1   _WIN32   _M_IX86=600   _M_IX86_FP=0   _MT   

This technique seems to include most macros that depend on command-line options, but excludes those that are always defined such as __FILE__ and __DATE__.

like image 83
cdev Avatar answered Oct 11 '22 09:10

cdev