This C code is underlined in the IDE and gives me an error:
uint64_t dummy = 1<<50;
unsigned long long dummy = 1<<50;
The “<<” is underlined, and hovering shows “Shift count >= width of type”.
I noticed this because this was not working either:
printf("%" PRIu64 "\n, dummy);
and I thought to just manually print each bit for debugging.
I’ve just realized I need to #include <inttypes.h> - this resolves the printf problem, but the 1<<50 problem is still present.
Am I doing something wrong (again)?
I think numbers default to int, you would need force the type: uint64_t dummy = (uint64_t)1<<50;
No. That does not work because you are trying to shift a 32 bit int which gives you a … 32 bit int. Casting the result to 64 bit does not change its value. What you must do is 1ull<<50 because 1ull is a 64 bit int with value 1
When manipulating uint64_t I usually define 1 and 0 as uint64_t variables to avoid manipulating 32bit int by mistake:
const uint64_t ONE = 1;
const uint64_t ZERO = 0;
const uint64_t ONES = ~ZERO;
uint64_t dummy = ONE << 50;
Sorry for the noise!