|
|
|
|
|
by dgrunwald
66 days ago
|
|
> ILP64 (wherein int is 64 bits) exists. It's not very popular, but it exists; e.g. ICC supports it. ILP64 is problematic for existing code: there is lots of stuff like hashcode computations using uint32_t with multiplications, relying on the C standard guaranteeing wraparound for unsigned overflows.
But with 64-bit int, uint32_t will promote to a signed int, and overflows will thus be undefined behavior.
This problem already exists with uint16_t multiplications on current architectures, but moving the problem to uint32_t will cause trouble for a lot of existing code that thought using fixed-size types like uint32_t would be safe. |
|
I chose to deal with this problem by doing a "pointless" operation to force a promotion to at least unsigned int. For example:
This piece of code will work on any machine, such as: (uint16_t = unsigned short = 16 bits, uint32_t = unsigned int = 32 bits); (uint16_t = unsigned short = unsigned int = 16 bits, uint32_t = unsigned long = 32 bits).