当我尝试在 gcc 4.9.1 中分配一个 128 位整数时,我收到一个警告:整数常量对于它的类型而言太大
。
示例代码
int main(void) {
__uint128_t p = 47942806932686753431;
return 0;
}
输出
我正在使用 gcc -std=c11 -o test test.c
进行编译,我得到:
test.c: In function ‘main’:
test.c:2:19: warning: integer constant is too large for its type
__uint128_t p = 47942806932686753431;
^
我是不是做错了什么或者这是 gcc 中的错误?
最佳答案
Am I doing something wrong or is this a bug in gcc?
问题在 47942806932686753431
部分,而不在 __uint128_t p
。根据gcc docs无法声明 128 位常量:
There is no support in GCC for expressing an integer constant of type __int128 for targets with long long integer less than 128 bits wide.
所以,看起来虽然你可以有 128 位的变量,但你不能有 128 位的常量,除非你的 long long
是 128有点宽。
解决方法可能是使用基本算术运算从“更窄”的整数常量构造 128 位值,并希望编译器执行 constant folding .
关于c - 在 C 中分配 128 位整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33318446/