#include <stdio.h>
#include <stdint.h>
int main(){
uint64_t a = 1 << 63;
/* do some thing */
return 0;
}
$ gcc -Wall -Wextra -std=c99 test.c -o test
warning: left shift count >= width of type [-Wshift-count-overflow]
问:uint64_t
应具有64个比特的宽度,所以左移位运算溢出?如何在C使用uint64_t中
1是'int'文字。使用'1ULL << 63'代替 –
@LưuVĩnhPhúcÇ指定'1'类型的_integer constant_'int'。 C中唯一指定的_literals_是_string literals_和_compound literals_。 '1'既不是那两个文字。 – chux
“为什么左移操作溢出?” - >哪一个首先发生:'1 << 63'或者它赋值给'uint64_t a'?由于'1 << 63'发生第一,它被分配给的类型是无关的'1 << 63'评估。 – chux