c - 在 C 中分配 128 位整数

标签 c gcc

当我尝试在 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/

相关文章:

c - 检测宏的使用? (错误号)

c - gcc:使用 nostdlib 编译时出现段错误

gcc - 如何解决QEMU GDB调试错误: Remote 'g' packet reply is too long?

c++ - 使用 printf 将 em-dash 打印到控制台窗口?

sql - 打开 c.isam 文件?

c - const关键字的使用

c++ - 使用 g++ 连接两个具有相同函数签名的强函数符号的结果,为什么?

GCC的异常处理模型

python - 如何将装饰器应用于用 C 编写的 Python 函数?

c - 有没有办法让这个功能更快? (C)