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
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:
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:
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.
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__.
Try the predef project. They maintain a database of predefined macros for many target platforms, host platforms and compiler toolchains.
They also have a script that attempts to discover all of the predefined names whether documented or not. It works by running the
strings
utility over the compiler, processing that to get plausible candidate tokens, and trying test compilations for each token. Not fast, but pretty good at discovering lots of macros.Get information at the source!
http://msdn.microsoft.com/en-us/library/b0084kay%28v=VS.90%29.aspx
/P
preprocessor flag will emit the currently active macros based on the project build settings. I am not sure if it is exactly the equivalent of gcc command you have shown. The output is in.I
file.