Preprocessor macro expansion to another preprocessor directive(预处理器宏扩展为另一个预处理器指令)
问题描述
最初我认为我需要这个,但我最终避免了它.然而,我的好奇心(以及对知识的渴望,哼)让我问:
Initially I thought I needed this, but I eventually avoided it. However, my curiosity (and appetite for knowledge, hum) make me ask:
可以一个预处理器宏,例如
Can a preprocessor macro, for instance in
#include "MyClass.h"
INSTANTIATE_FOO_TEMPLATE_CLASS(MyClass)
扩展到另一个包含,如 in
expand to another include, like in
#include "MyClass.h"
#include "FooTemplate.h"
template class FooTemplate<MyClass>;
?
推荐答案
相信做不到,这是因为预处理器是single pass.所以它不能发出其他预处理器指令.
I believe that cannot be done, this is because the pre-processor is single pass. So it cannot emit other preprocessor directives.
具体来说,来自 C99 标准(6.10.3.4 第 3 段):
Specifically, from the C99 Standard (6.10.3.4 paragraph 3):
3 结果完全宏替换预处理令牌序列不被处理为预处理指令,即使它像一个,...
3 The resulting completely macro-replaced preprocessing token sequence is not processed as a preprocessing directive even if it resembles one, ...
有趣的是,这就是为什么将一元 _Pragma 运算符添加到 c99 中的原因.因为 #pragma 不能由宏发出,但 _Pragma 可以.
Interestingly enough, This is why the unary _Pragma operator was added to c99. Because #pragma could not be emited by macros, but _Pragma can.
这篇关于预处理器宏扩展为另一个预处理器指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:预处理器宏扩展为另一个预处理器指令
基础教程推荐
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 提升 ASIO 流缓冲 2021-01-01
- c++ STL设置差异 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
