如何找出cl.exe时内置的宏 [英] How to find out cl.exe's built-in macros

查看:775
本文介绍了如何找出cl.exe时内置的宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道我怎么能找出哪些是cl.exe时的内置/ predefined宏?
例如,对于GCC以下命令行会列出编译器的所有内置宏

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

编辑:我感兴趣的类似于GCC的方式,是问实际编译

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

感谢

推荐答案

这方法确实金额要求predefined宏的列表中,编译器,但是它使用无证功能,只提供了部分清单。我在这里包括它的完整性。

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.

微软C / C ++编译器允许另一种编译器前端使用/ B1和/ Bx的命令行调用分别为开关.c和.cpp文件。命令行接口模块CL.EXE传递的选项,通过MSC_CMD_FLAGS环境变量替换编译器前端的列表。此选项列表包括了一些predefined宏-D宏定义。

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;
}

编译此名为可执行文件,例如MyC1.exe,确保它是在路径中可见的,并告诉CL.EXE调用它作为使用下列之一的编译器前端:

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

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

包含以查看哪些宏pdefined该组选项$ P $所需的其他命令行选项。

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

在输出结果认准-D选项。一个例子列表如下。在实际输出的名单将在空格分隔,与-D pceded每个宏定义$ P $,和其他选项也present。

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

_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

此技术似乎包括依赖于命令行选项最宏,但不包括那些始终定义,如__FILE__和__DATE __

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__.

这篇关于如何找出cl.exe时内置的宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆