how to use uint64_t in C
c
Solution
`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)
Problem
``` #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?