X宏生成杂散运算符(X Macro generate stray operator)
我尝试创建一个宏来定义X,但08和09被编译器误解为杂散运算符。 为什么这些失败时,其他人工作正常?
#define LIST_TEST_X \ X(A,01)\ X(B,02)\ X(C,03)\ X(D,04)\ X(E,05)\ X(F,06)\ X(G,07)\ X(H,08)\ X(I,09)\ X(K,10) enum XEnum { #define X(A, b) A=b, LIST_TEST_X #undef X };I try to create a macro to define X, but 08 and 09 are misinterpreted by the compiler as a stray operator. Why do these fail when the others work fine?
#define LIST_TEST_X \ X(A,01)\ X(B,02)\ X(C,03)\ X(D,04)\ X(E,05)\ X(F,06)\ X(G,07)\ X(H,08)\ X(I,09)\ X(K,10) enum XEnum { #define X(A, b) A=b, LIST_TEST_X #undef X };最满意答案
以0开始的整型常量是八进制常量。 由于8和9不是有效数字,所以08和09将不能编译。
要么删除常量上的前导零,要么将它们替换为空格。
Integer constants that start with a 0 are octal constants. Since 8 and 9 are not valid digits, 08 and 09 will not compile.
Either remove the leading zeroes on your constants, or replace them with spaces.
更多推荐
发布评论