gpt4 book ai didi

c - 预处理器宏 GCC : pasting x and x does not give a valid preprocessing token

转载 作者:太空狗 更新时间:2023-10-29 17:26:18 26 4
gpt4 key购买 nike

#define  PATH  "yagh/headers/"
#define FILNAME "includefile"


#define CONCAT(a__, b__) CONCAT_DO(a__, b__)
#define CONCAT_DO(a__, b__) a__##b__
#define CONCATTHREE(a__, b__, c__) CONCAT(CONCAT(a__, b__), c__)
#define STRINGIFY(a__) #a__


#include STRINGIFY(CONCATTHREE(PATH ,FILNAME ,.h));

此宏在 VS 编译器中运行良好,但在 GCC 编译器上无法编译:

Error: error: pasting "/" and "includefile" does not give a valid preprocessing token

对于某些包含文件,它会给出错误:

Error: pasting "includefile" and "." does not give a valid preprocessing token

最佳答案

GCC 在执行 C 标准方面更加严格:参见 Differences in Macro ## concatenation operator between Visual-C++ and gcchttp://gcc.gnu.org/onlinedocs/gcc-4.3.3/cpp/Concatenation.html#Concatenation .

您可以尝试 #include STRINGIFY(PATH FILNAME.h)(FILNAME.h 之间缺少空格很重要)- - 这对我适用于 gcc 4.6.3。

关于c - 预处理器宏 GCC : pasting x and x does not give a valid preprocessing token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4667779/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com