Escaping a # symbol in a #define macro?(在#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 宏中转义# 符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在#define 宏中转义# 符号?
基础教程推荐
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- c++ STL设置差异 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
