Would it make sense to use BIT(31)?
On Thu, Jan 7, 2021 at 2:20 PM Matt DeVillier matt.devillier@gmail.com wrote:
`1u << 31` is correct, clear, and easy to read/understand quickly. It has my vote.
On Thu, Jan 7, 2021 at 3:42 PM Nico Huber nico.h@gmx.de wrote:
Hi coreboot fellows,
another patch that fixes a `1 << 31` to `1UL << 31` [1] reminded me that some people objected to such changes. I'm not sure if we ever draw a conclusion on the matter.
`1 << 31` is undefined behavior because the `1` can (and thus will) be represented as a (signed) `int` which is limited by 2^31-1 for all our targets. But we know very well that GCC (and I assume Clang too) do the right thing: Produce a value that when casted to an `unsigned int` is converted to 2^31.
So, it's wrong but not broken ;) and any suffix to the `1` makes it a bit harder to read.
What do you think? Should we allow such changes? Should we normalize on any style?
If we want to make it defined behavior, my personal preference would be `1u << 31`. Lower case because it's more distinct from the number part, and we actually don't need a long (that might even hide actual errors if we want a 32-bit limited value).
Cheers, Nico
PS. Happy new year btw. :D
[1] https://review.coreboot.org/c/coreboot/+/49076 _______________________________________________ coreboot mailing list -- coreboot@coreboot.org To unsubscribe send an email to coreboot-leave@coreboot.org
coreboot mailing list -- coreboot@coreboot.org To unsubscribe send an email to coreboot-leave@coreboot.org