C 预处理器:动态#Define 创建

C Preprocessor: Dynamic #Define Creation

我想要扩展这些 C 预处理器行:

#define _POUND_ #define
_POUND_ _FALSE 0
_FALSE

展开所以最后一行(即 _FALSE) 展开为 0。我知道递归 CPP 不可能直接实现,但它 can be done。不幸的是,我不确定我是否遵循link.

中呈现的逻辑

我想我需要强制进行额外的评估,但我不知道在这种情况下该怎么做(即我已经尝试过但失败了)。

你能帮忙吗?

正如评论中多次指出的那样,您正在寻找的内容不受支持。以下是标准对此的说明:

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 的宏扩展不会导致 bona fide 要创建的预处理指令。宏可以扩展为具有预处理指令形式的文本,但此类文本实际上不能是指令。

确实会重新扫描宏扩展产生的文本以查找更多要扩展的宏,但该过程不涉及识别不存在的预处理指令。