Normally, C requires that a binary operator's operands are promoted to the type of the higher-ranking operand. This can be exploited to avoid filling code with verbose casts, for example:
if (x-48U<10) ...
y = x+0ULL << 40;
etc.
However, I've found that, at least with gcc, this behavior does not work for bitshifts. I.e.
int x = 1;
unsigned long long y = x << 32ULL;
I would expect the type of the right-hand operand to cause the left-hand operand to be promoted to unsigned long long so that the shift succeeds. But instead, gcc prints a warning:
warning: left shift count >= width of type
Is gcc broken, or does the standard make some exception to the type promotion rules for bitshifts?
#define ULL(x) ((unsigned long long)x)? - Borealid<<32. @Borealid: Yes I could, but I like writing code that can be copy-and-pasted anywhere (e.g. other projects) without requiring extra defines/headers. I hate things liketypedef unsigned int uint;. - R.. GitHub STOP HELPING ICEstdint.h.uint64_tis a 64-bit unsigned value. That's portable to most every platform. - Borealid