3 ms·
It's important to notice the disclaimer that this is applies to x86/x86-64 GCC like platforms, in particular int is assumed to be 32 bits. As antirez said as w
by jstimpfle 4y ago
It's important to notice the disclaimer that this is applies to x86/x86-64 GCC like platforms, in particular int is assumed to be 32 bits.
As antirez said as well, I don't pride myself in understanding the intricacies of integer arithmetic and promotion well. I try to write clear code by writing around the less commonly understood rules. Nevertheless I wanted to test myself. There are two questions that surprised me somewhat.
Apparently you can't left-shift a negative value even by a zero amount, as in (-1 << 0).
And is it true that the value of "-1L > 1U" is platform dependent? I had assumed that 1U would be promoted to 1L in this expression, even on x86 where unsigned int and long have the same number of bits. According to the following document, long int has a "higher rank" than unsigned int. https://wiki.sei.cmu.edu/confluence/display/c/INT02-C.+Understand+integer+conversion+rules https://wiki.sei.cmu.edu/confluence/display/c/INT02-C.+Under... . (Edit: according to rules 4 and 5 of "Usual arithmetic conversions", it's not only the rank but also about "the values that can be represented")