X宏生成杂散运算符(X Macro generate stray operator)

编程入门 行业动态 更新时间:2024-10-20 01:36:23
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.

更多推荐

本文发布于:2023-08-07 00:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1457874.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:运算符   Macro   generate   stray   operator

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!