在#define 宏中转义# 符号? [英] Escaping a # symbol in a #define macro?

查看:34
本文介绍了在#define 宏中转义# 符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在不涉及血淋淋的细节的情况下,我想使用一个 #define 宏,该宏将扩展为一个 #include 但#"符号会混淆预处理器(如它认为我想引用一个论点.)

Without going into the gory details I want to use a #define macro that will expand to a #include but the '#' sign is confusing the preprocessor (as it thinks I want to quote an argument.)

例如,我想做这样的事情:

For example, I want to do something like this:

#define MACRO(name) #include "name##foo"

然后这样使用它:

MACRO(Test)

这将扩展为:

#include "Testfoo"

不起眼的 # 符号导致预处理器出错.MinGW 给我以下错误:

The humble # sign is causing the preprocessor to barf. MinGW gives me the following error:

'#'后面没有宏参数

我想我需要转义 # 符号,但如果这可能的话我不会.

I guess I need to escape the # sign but I don't if this is even possible.

是的,宏确实是邪恶的……

Yes, macros are indeed evil...

推荐答案

据我所知,你不能在定义中使用另一个预处理器指令.

As far as I remember you cannot use another preprocessor directive in define.

这篇关于在#define 宏中转义# 符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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