我正在尝试用C语言编写宏,以便创建正确的#pragma声明。
_pragma(section .BLOCK1) //Correct but deprecated
_pragma(section ".BLOCK1") //Correct without warning
以下代码可以运行,但编译器会给出警告(弃用声明):
#define DO_PRAGMA(x) _Pragma(#x)
#define PRAGMA(number) \
DO_PRAGMA(section .BLOCK##number)
PRAGMA(1)
我该如何在宏中包含双引号? 我已经尝试插入 "\"", 但是由于字符串直接被解释,所以它不起作用。
section _stringify(.BLOCK123)
(Eclipse的宏扩展也会返回相同的结果)。我不确定这是否正确(也许编译器可以在第二步中解决它)。 - Andreagcc -E
命令检查扩展。 - enscPRAGMA(1)
应该能展开为_Pragma("section \".BLOCK1\"")
,所以我认为这就是你需要的。 - anastaciu