如何获得所有预修指令及其值的清单?特别是#define [英] How can I get a list of all preprecoesor directives and their values ? specifically #define

查看:99
本文介绍了如何获得所有预修指令及其值的清单?特别是#define的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





在大型项目上工作时,不可避免地会有数百万个预处理器包裹的代码,请看



#ifdef MY_COMPLETE_MISLEADING_NAME

//一些东西

#endif



所以我想要看我何时编译了哪些预处理器指令被定义,哪些不是。我在谈论VS 2015。所以我希望能够选择构建配置,即prod / release / debug,然后让pre-p解析代码并提取定义的所有值并列出它们,超级快速预编译。



有人知道怎么做吗?







我尝试了什么:



我可以放手册代码来查看值。所以我尝试创建一个虚拟文件并执行此操作



bool PREP_STUPID_NAME1 = false;

#ifdef STUPID_NAME1

PREP_STUPID_NAME1 = true;

#endif



呵呵这是一个问题,任何天才的预处理器专家都可以写一个宏那将自动生成我正在谈论的文件?因此解析所有代码,将所有定义粘贴到文件中,为每个代码创建一个bool,然后重复上面的代码等





Marcus

Hi,

Working on huge projects, inevitably there are millions of pre-processor wrapped code, s owe see

#ifdef MY_COMPLETE_MISLEADING_NAME
//some stuff
#endif

So I want to see when I compile which of these pre-processor directives are defined and which are not. I am talking about VS 2015.So I would love to be able to chose a build config ie prod/release/debug and then just let the pre-p parse the code and pull out all the values of the defines and list them, super quick as its pre compilation.

Anybody know how to do this?



What I have tried:

I can put manual code in to see the values. So I've tried creating a dummy file and doing this

bool PREP_STUPID_NAME1 = false;
#ifdef STUPID_NAME1
PREP_STUPID_NAME1 = true;
#endif

Hehe that's a point, any genius pre-processor gurus out there that could write a macro that would automatically generate the file I am talking about ? So parse all the code, stick all the defines in a file, create a bool for each one, and then repeat the above code etc


Marcus

推荐答案

VS编译器没有选项。



但是如果可以安装GCC / G ++(或已经有)你可以使用 -dM -E 选项。



另请参阅 C / C ++提示:如何列出编译器预定义宏| Nadeau Software [ ^ ]供其他编制者使用。





要处理项目中的所有输入文件,您可以创建自定义构建规则对每个源文件执行。该工具可以是自编写的解析器,也可以是带有可选后处理的GCC / G ++(另一种用于过滤和格式化的自创工具)。过滤工具的候选者是正则表达式命令行实用程序。如果您对Linux有所了解,可以使用 Native Win32端口中的 grep sed 一些GNU实用程序 [ ^ ](UnxUtils)。

[/ EDIT]
There is no option for the VS compiler.

But if you can install GCC/G++ (or have it already) you can use that with the -dM -E options.

See also C/C++ tip: How to list compiler predefined macros | Nadeau Software[^] for other compilers.


To process all input files from a project you can create a Custom Build Rule that is executed for each source file. The tool may be a self written parser or just the GCC/G++ with optional post-processing (another self created tool for filtering and formatting). Candidates for filtering tools are regular expression command line utilities. If you know Linux a little bit, you may use grep and sed from the Native Win32 ports of some GNU utilities[^] (UnxUtils).
[/EDIT]


您可以执行简单的编译指示消息/警告...可能比在大型项目中溢出每个预处理器定义的所有内容更简单。 br />
You can do simple pragma messages/warnings... probably simpler than spilling all the contents of every pre-processor definition in a large project.
#ifdef SOMEVAR
  #pragma message("SOMEVAR is defined here")
#else
  #pragma message("SOMEVAR is NOT defined here")
#endif



Pragma message [ ^ ]


这篇关于如何获得所有预修指令及其值的清单?特别是#define的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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