有什么工具可以测试C/C ++扩展#define宏吗? [英] Any utility to test expand C/C++ #define macros?

查看:87
本文介绍了有什么工具可以测试C/C ++扩展#define宏吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎我经常花太多时间尝试获取#define宏来完全执行我想要的操作.我将在下面发布当前的困境,我们将为您提供任何帮助.但是,实际上更大的问题是,有人可以推荐任何实用工具来快速显示宏的实际作用吗?如果我能看到什么地方出了问题,看来即使是缓慢的试错过程也会更快.

It seems I often spend way too much time trying to get a #define macro to do exactly what i want. I'll post my current dilemma below and any help is appreciated. But really the bigger question is whether there is any utility someone could recommend, to quickly display what a macro is actually doing? It seems like even the slow trial and error process would go much faster if I could see what is wrong.

当前,我正在从我制作的DLL中动态加载一长串函数.我设置方法的方式是,函数指针与导出的函数具有相同的名称,用于原型化它们的typedef具有相同的名称,但带有下划线.因此,我想使用一个定义来简化一长串的函数指针的分配.

Currently, I'm dynamically loading a long list of functions from a DLL I made. The way I've set things up, the function pointers have the same nanes as the exported functions, and the typedef(s) used to prototype them have the same names, but with a prepended underscore. So I want to use a define to simplify assignments of a long long list of function pointers.

例如,在下面的代码语句中,"hexdump"是类型定义函数点的名称,也是函数的名称,而_hexdump是类型定义的名称.如果GetProcAddress()失败,则失败计数器递增.

For example, In the code statement below, 'hexdump' is the name of a typedef'd function point, and is also the name of the function, while _hexdump is the name of the typedef. If GetProcAddress() fails, a failure counter in incremented.

if (!(hexdump = (_hexdump)GetProcAddress(h, "hexdump"))) --iFail;

因此,假设我要用宏替换上面的每一行,就像这样...

So let's say I'd like to replace each line like the above with a macro, like this...

GETADDR_FOR(hexdump )

这是到目前为止我能想到的最好的.它不起作用(我的//评论只是为了防止消息中的文本格式设置)...

Well this is the best I've come up with so far. It doesn't work (my // comment is just to prevent text formatting in the message)...

// #define GETADDR_FOR(a) if (!(a = (#_#a)GetProcAddress(h, "/""#a"/""))) --iFail; 

再次,当我对自己犯下的愚蠢错误有所了解时,拥有一个实用程序,只需插入宏即可向我展示自己的方式上的错误.

And again, while I'd APPRECIATE an insight into what silly mistake I've made, it would make my day to have a utility that would show me the error of my ways, by simply plugging in my macro.

推荐答案

转到 https://godbolt.org/.在左窗格中输入代码,然后选择gcc作为编译器,在右窗格中将参数作为-E.预处理后的代码将显示在右侧.

Go to https://godbolt.org/. Enter your code in the left pane and select compiler as gcc put the argument as -E in the right pane. Your pre-processed code will appear on the right.

这篇关于有什么工具可以测试C/C ++扩展#define宏吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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