无需预处理器即可扩展C / C ++函数宏 [英] Expand C/C++ function macros without preprocessor

查看:74
本文介绍了无需预处理器即可扩展C / C ++函数宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不通过预处理程序运行的情况下测试/扩展C / C ++文件中的所有功能宏?
例如,是否有一个程序或方法可以对此进行更改:

How would I test/expand all the function macros, in a C/C++ file, without running it through a preprocessor? For example, is there a program or method which would change this:

#include <iostream>
#define AAA(a) cout << "function "  << a << endl
using namespace std;
int main(){
AAA(12);
}

是这个吗?

#include <iostream>
using namespace std;
int main(){
cout << "function " << 12 << endl;
}

我不想运行预处理器,因为文件中的所有包含项使 gcc -E<>输出变得非常丑陋,我只想要几个简单的宏扩展而没有所有开销。

I don't want to run through preprocessor because all the includes in the files make the "gcc -E <>" output really ugly, I just want a couple simple macro expansions without all the overhead.

推荐答案

不,这不可能。例如,您包含的标头可能包含要在正文中扩展的宏。还是您的意思是不扩展标题中的任何宏?在这种情况下,预处理器绝对无法区分您想要的东西和不需要的东西。

No, it's not possible. Your included headers could include macros that you want to expand in the body, for example. Or did you mean to not expand any macros that come from headers? The preprocessor has absolutely no way of distinguishing what you want from what you don't want in this case.

如果您事先知道不是这种情况,那么我建议简单地编写脚本以删除包含文件,然后通过预处理程序运行该脚本。

If you know in advance this is not the case, then I recommend simply writing a script to remove the includes and then run that through the preprocessor.

这篇关于无需预处理器即可扩展C / C ++函数宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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