How to Use Uint64_T in C [Duplicate]
#Include #Include Int Main(){ Uint64_T a = 1 = Width of Type [-Wshift-Count-Overflow] Q: Uint64_T Should Have 64 Bits Width, Why the Left Shift Operation...
#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]
Q: uint64_t should have 64 bits width, why the left shift operation overflows?
1 is an int which is either only 32 bits on your platform, or it could be 64 bits but signed.
Use (uint64_t)1 << 63 to cast 1 to 64-bit unsigned integer first. (Or ((uint64_t)1) << 63 if you prefer)