错误:无效后缀“b11111111111111111111111111111111”关于整数常量
我在 RHEL 5.7 x86_64 机器上使用 g++ 版本 4.1.2。这与 RHEL 6.0 x86_64 附带的 g++ 版本 4.4.5 构建得很好。这个编译器错误是什么意思以及如何修复它?
[mehoggan@hoggant35002 C]$ g++ -Wall -o binary ./binary.cpp
./binary.cpp:2:5: error: invalid suffix "b11111111111111111111111111111111" on integer constant
./binary.cpp:3:5: error: invalid suffix "b11111111111111111111111111111110" on integer constant
./binary.cpp:4:5: error: invalid suffix "b11111111111111111111111111111100" on integer constant
./binary.cpp:5:5: error: invalid suffix "b11111111111111111111111111111000" on integer constant
./binary.cpp:6:5: error: invalid suffix "b11111111111111111111111111110000" on integer constant
./binary.cpp:7:5: error: invalid suffix "b11111111111111111111111111100000" on integer constant
./binary.cpp:8:5: error: invalid suffix "b11111111111111111111111111000000" on integer constant
./binary.cpp:9:5: error: invalid suffix "b11111111111111111111111110000000" on integer constant
./binary.cpp:10:5: error: invalid suffix "b11111111111111111111111100000000" on integer constant
./binary.cpp:11:5: error: invalid suffix "b11111111111111111111111000000000" on integer constant
./binary.cpp:12:5: error: invalid suffix "b11111111111111111111110000000000" on integer constant
./binary.cpp:13:5: error: invalid suffix "b11111111111111111111100000000000" on integer constant
./binary.cpp:14:5: error: invalid suffix "b11111111111111111111000000000000" on integer constant
./binary.cpp:15:5: error: invalid suffix "b11111111111111111110000000000000" on integer constant
./binary.cpp:16:5: error: invalid suffix "b11111111111111111100000000000000" on integer constant
./binary.cpp:17:5: error: invalid suffix "b11111111111111111000000000000000" on integer constant
./binary.cpp:18:5: error: invalid suffix "b11111111111111110000000000000000" on integer constant
./binary.cpp:19:5: error: invalid suffix "b11111111111111100000000000000000" on integer constant
./binary.cpp:20:5: error: invalid suffix "b11111111111111000000000000000000" on integer constant
./binary.cpp:21:5: error: invalid suffix "b11111111111110000000000000000000" on integer constant
./binary.cpp:22:5: error: invalid suffix "b11111111111100000000000000000000" on integer constant
./binary.cpp:23:5: error: invalid suffix "b11111111111000000000000000000000" on integer constant
./binary.cpp:24:5: error: invalid suffix "b11111111110000000000000000000000" on integer constant
./binary.cpp:25:5: error: invalid suffix "b11111111100000000000000000000000" on integer constant
./binary.cpp:26:5: error: invalid suffix "b11111111000000000000000000000000" on integer constant
./binary.cpp:27:5: error: invalid suffix "b11111110000000000000000000000000" on integer constant
./binary.cpp:28:5: error: invalid suffix "b11111100000000000000000000000000" on integer constant
./binary.cpp:29:5: error: invalid suffix "b11111000000000000000000000000000" on integer constant
./binary.cpp:30:5: error: invalid suffix "b11110000000000000000000000000000" on integer constant
./binary.cpp:31:5: error: invalid suffix "b11100000000000000000000000000000" on integer constant
./binary.cpp:32:5: error: invalid suffix "b11000000000000000000000000000000" on integer constant
./binary.cpp:33:5: error: invalid suffix "b10000000000000000000000000000000" on integer constant
代码:
static int s_bitCountMask[32] = {
0b11111111111111111111111111111111,
0b11111111111111111111111111111110,
0b11111111111111111111111111111100,
0b11111111111111111111111111111000,
0b11111111111111111111111111110000,
0b11111111111111111111111111100000,
0b11111111111111111111111111000000,
0b11111111111111111111111110000000,
0b11111111111111111111111100000000,
0b11111111111111111111111000000000,
0b11111111111111111111110000000000,
0b11111111111111111111100000000000,
0b11111111111111111111000000000000,
0b11111111111111111110000000000000,
0b11111111111111111100000000000000,
0b11111111111111111000000000000000,
0b11111111111111110000000000000000,
0b11111111111111100000000000000000,
0b11111111111111000000000000000000,
0b11111111111110000000000000000000,
0b11111111111100000000000000000000,
0b11111111111000000000000000000000,
0b11111111110000000000000000000000,
0b11111111100000000000000000000000,
0b11111111000000000000000000000000,
0b11111110000000000000000000000000,
0b11111100000000000000000000000000,
0b11111000000000000000000000000000,
0b11110000000000000000000000000000,
0b11100000000000000000000000000000,
0b11000000000000000000000000000000,
0b10000000000000000000000000000000,
};
#include <stdio.h>
int main(int argc, char *argv[])
{
for (int i = 0; i < 32; i++) {
printf("%d\n",s_bitCountMask[i]);
}
}
I am using g++ version 4.1.2 on a RHEL 5.7 x86_64 box. This builds just fine with g++ version 4.4.5 which comes with RHEL 6.0 x86_64. What does this compiler error mean and how do you fix it?
[mehoggan@hoggant35002 C]$ g++ -Wall -o binary ./binary.cpp
./binary.cpp:2:5: error: invalid suffix "b11111111111111111111111111111111" on integer constant
./binary.cpp:3:5: error: invalid suffix "b11111111111111111111111111111110" on integer constant
./binary.cpp:4:5: error: invalid suffix "b11111111111111111111111111111100" on integer constant
./binary.cpp:5:5: error: invalid suffix "b11111111111111111111111111111000" on integer constant
./binary.cpp:6:5: error: invalid suffix "b11111111111111111111111111110000" on integer constant
./binary.cpp:7:5: error: invalid suffix "b11111111111111111111111111100000" on integer constant
./binary.cpp:8:5: error: invalid suffix "b11111111111111111111111111000000" on integer constant
./binary.cpp:9:5: error: invalid suffix "b11111111111111111111111110000000" on integer constant
./binary.cpp:10:5: error: invalid suffix "b11111111111111111111111100000000" on integer constant
./binary.cpp:11:5: error: invalid suffix "b11111111111111111111111000000000" on integer constant
./binary.cpp:12:5: error: invalid suffix "b11111111111111111111110000000000" on integer constant
./binary.cpp:13:5: error: invalid suffix "b11111111111111111111100000000000" on integer constant
./binary.cpp:14:5: error: invalid suffix "b11111111111111111111000000000000" on integer constant
./binary.cpp:15:5: error: invalid suffix "b11111111111111111110000000000000" on integer constant
./binary.cpp:16:5: error: invalid suffix "b11111111111111111100000000000000" on integer constant
./binary.cpp:17:5: error: invalid suffix "b11111111111111111000000000000000" on integer constant
./binary.cpp:18:5: error: invalid suffix "b11111111111111110000000000000000" on integer constant
./binary.cpp:19:5: error: invalid suffix "b11111111111111100000000000000000" on integer constant
./binary.cpp:20:5: error: invalid suffix "b11111111111111000000000000000000" on integer constant
./binary.cpp:21:5: error: invalid suffix "b11111111111110000000000000000000" on integer constant
./binary.cpp:22:5: error: invalid suffix "b11111111111100000000000000000000" on integer constant
./binary.cpp:23:5: error: invalid suffix "b11111111111000000000000000000000" on integer constant
./binary.cpp:24:5: error: invalid suffix "b11111111110000000000000000000000" on integer constant
./binary.cpp:25:5: error: invalid suffix "b11111111100000000000000000000000" on integer constant
./binary.cpp:26:5: error: invalid suffix "b11111111000000000000000000000000" on integer constant
./binary.cpp:27:5: error: invalid suffix "b11111110000000000000000000000000" on integer constant
./binary.cpp:28:5: error: invalid suffix "b11111100000000000000000000000000" on integer constant
./binary.cpp:29:5: error: invalid suffix "b11111000000000000000000000000000" on integer constant
./binary.cpp:30:5: error: invalid suffix "b11110000000000000000000000000000" on integer constant
./binary.cpp:31:5: error: invalid suffix "b11100000000000000000000000000000" on integer constant
./binary.cpp:32:5: error: invalid suffix "b11000000000000000000000000000000" on integer constant
./binary.cpp:33:5: error: invalid suffix "b10000000000000000000000000000000" on integer constant
The code:
static int s_bitCountMask[32] = {
0b11111111111111111111111111111111,
0b11111111111111111111111111111110,
0b11111111111111111111111111111100,
0b11111111111111111111111111111000,
0b11111111111111111111111111110000,
0b11111111111111111111111111100000,
0b11111111111111111111111111000000,
0b11111111111111111111111110000000,
0b11111111111111111111111100000000,
0b11111111111111111111111000000000,
0b11111111111111111111110000000000,
0b11111111111111111111100000000000,
0b11111111111111111111000000000000,
0b11111111111111111110000000000000,
0b11111111111111111100000000000000,
0b11111111111111111000000000000000,
0b11111111111111110000000000000000,
0b11111111111111100000000000000000,
0b11111111111111000000000000000000,
0b11111111111110000000000000000000,
0b11111111111100000000000000000000,
0b11111111111000000000000000000000,
0b11111111110000000000000000000000,
0b11111111100000000000000000000000,
0b11111111000000000000000000000000,
0b11111110000000000000000000000000,
0b11111100000000000000000000000000,
0b11111000000000000000000000000000,
0b11110000000000000000000000000000,
0b11100000000000000000000000000000,
0b11000000000000000000000000000000,
0b10000000000000000000000000000000,
};
#include <stdio.h>
int main(int argc, char *argv[])
{
for (int i = 0; i < 32; i++) {
printf("%d\n",s_bitCountMask[i]);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这意味着旧版本的 g++ 不接受
0b000
二进制常量语法。您可以将数字重写为十六进制 - 二进制可以一次轻松地转换为十六进制四位:It means the older verison of g++ won't accept the
0b000
binary constant syntax. You can rewrite the numbers as hex instead - binary easily translates into hex four bits at a time:Rup对此有正确的答案。但我要补充一点:
根据您访问该表的方式,使用以下命令当场生成值可能更合适:
或者,您也可以这样声明该表:
*假设
-1
全部为一位(现在几乎每台机器上都有)。Rup has the correct answer to this. But I'll add this:
Depending on how you're accessing that table, it might be more appropriate to just generate the value on the spot with this:
Alternatively, you could also declare the table like this:
*Assuming that
-1
is all one-bits (which it is on nearly every machine now).