3 ms·
Thanks, I just noticed a small mistake in my example (I don't trigger the UB because I access b[0] containing 0x80 without shifting, however I meant to do it th
by themulticaster 5y ago
Thanks, I just noticed a small mistake in my example (I don't trigger the UB because I access b[0] containing 0x80 without shifting, however I meant to do it the other way around).
Still, adding an explicit cast to the left operand seems to be enough to avoid this, e.g.:
uint32_t x = ((uint32_t)b[0]) << 24;
In summary, I think my point that using unsigned char would be appropriate in this case still stands.
- cygx 5y ago> Still, adding an explicit cast to the left operand seems to be enough to avoid this Indeed. See my other comment, https://news.ycombinator.com/item?id=27086482 https://news.ycombinator.com/item?id=27086482