10 ms·
Why mask and then shift instead of casting to the correct type and then shifting, like this: (uint32_t)x[0] << 24 | ... Of course, this requires that x[0]
by amluto 6y ago
Why mask and then shift instead of casting to the correct type and then shifting, like this:
(uint32_t)x[0] << 24 | ...
Of course, this requires that x[0] be unsigned.
- syockit 6y agoIf this is for deserialisation then it's okay for x[0] to be signed. You just need to recast the result as int32_t (or simply assign to an int32_t variable without any cast) and it is not UB.