我想要扩展这些 C 预处理器行:
#define _POUND_ #define
_POUND_ _FALSE 0
_FALSE
展开,最后一行(即_FALSE)
展开为0。我知道递归CPP不可能直接实现,但它can be done 。不幸的是,我不完全确定我遵循了此链接中提出的逻辑。
我认为我需要强制进行额外的评估,但我不知道在这种情况下该怎么做(即我已经尝试过但失败了)。
你能帮忙吗?
最佳答案
正如评论中多次指出的,您正在寻找的内容不受支持。以下是该标准对此的规定:
A preprocessing directive consists of a sequence of preprocessing tokens that satisfies the following constraints: The first token in the sequence is a # preprocessing token that (at the start of translation phase 4) is either the first character in the source file (optionally after white space containing no new-line characters) or that follows white space containing at least one new-line character.
(C2011,6.10/2;已添加重点)
翻译阶段 4 是执行预处理指令的阶段,因此阶段 4 期间的宏扩展不能导致创建真正的预处理指令。宏可以扩展到具有预处理指令形式的文本,但这样的文本实际上不能是指令。
确实,宏扩展产生的文本会重新扫描以扩展更多宏,但该过程不涉及识别尚不存在的预处理指令。
关于C预处理器: Dynamic#Define Creation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37058951/