gpt4 book ai didi

c - 错误: '#' is not followed by a macro parameter

转载 作者:行者123 更新时间:2023-11-30 14:36:22 33 4
gpt4 key购买 nike

我正在尝试编写一个宏,为 C 中任何给定对象类的对象池生成代码。每当我运行预处理器时,我总是收到错误:'#'后面没有宏参数

我尝试将 x##y 替换为:

#define CONCAT1(x, y) x##y
#define CONCAT2(x, y) CONCAT1(x, y)

因为这是在类似问题中建议的

#define CONCAT1(x, y) x##y
#define CONCAT2(x, y) CONCAT1(x, y)

#define DECLARE_POOL(CLASS, LEVEL1, LEVEL2) {\
\
#define CONCAT2(CLASS, _Pool_Level1) LEVEL1\
#define CONCAT2(CLASS, _Pool_Level2) LEVEL2\
\
CLASS* CONCAT2(CLASS, _Pool)[LEVEL1] = { 0 };\
\
int CONCAT2(CLASS, _Available_Head) = -1;\
int CONCAT2(CLASS, _Available_Tail) = -1;\
\
int CONCAT2(CLASS, _In_Use_Head) = -1;\
int CONCAT2(CLASS, _In_Use_Tail) = -1;\
\
int CONCAT2(CLASS, _Increase_Pool)(int Level1_Address){\
\
}\
\
int CLASS(int Address) {\
\
}\
\
int CONCAT2(CLASS, _Delete)(int Address) {\
\
}\
\
int CONCAT2(CLASS, s)(int Address)\
\
}\
\
int CONCAT2(CLASS, _Save_All)(void)\
\
}\
\
int CONCAT2(CLASS, _Restore_All)(void)\
\
}\
int CONCAT2(CLASS, _Free_All)(void)\
\
}\
}

预期:代码通过预处理器并给出“CLASS”类型对象的函数原型(prototype)
实际结果:

error: '#' is not followed by a macro parameter
#define DECLARE_POOL(CLASS, LEVEL1, LEVEL2) {\

最佳答案

您不能在宏内使用#define。或任何其他预处理器指令,就此而言。

关于c - 错误: '#' is not followed by a macro parameter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58108870/

33 4 0