本文介绍了将预处理器宏扩展为另一个预处理器指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
最初,我以为我需要这个,但最终我避免了.但是,我的好奇心(以及对知识的渴望,嗡嗡声)使我问:
Initially I thought I needed this, but I eventually avoided it. However, my curiosity (and appetite for knowledge, hum) make me ask:
例如可以在
#include "MyClass.h"
INSTANTIATE_FOO_TEMPLATE_CLASS(MyClass)
扩展到另一个包含项,例如
expand to another include, like in
#include "MyClass.h"
#include "FooTemplate.h"
template class FooTemplate<MyClass>;
?
推荐答案
我认为无法完成,这是因为预处理程序是单遍.因此它不能发出其他预处理器指令.
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):
足够有趣,这就是为什么将一元_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.
这篇关于将预处理器宏扩展为另一个预处理器指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!