3 ms·
The correct and portable solution is to not use uint32_t, but to use uint8_t, and construct the integers manually.
by Sagiri 10y ago
The correct and portable solution is to not use uint32_t, but to use uint8_t, and construct the integers manually.
- stephencanon 10y agoWell, portable except for `uint8_t` not being guaranteed to exist. =)
- Thiez 10y agoWhich is a feature! If you use `char` instead of `uint8_t` your program would still compile on a system that doesn't have `uint8_t`, but it is likely to do something entirely unexpected. At least when you use `uint8_t` you are warned at compile-time that your program is broken.
- Sagiri 10y agoIt isn't? At least that would be a failure at compile-time, rather than run-time.
- stephencanon 10y ago`uint8_t` cannot exist on any platform with `CHAR_BIT > 8`. Such platforms are non-existent in the mainstream CPU world, but surprisingly common in the DSP world. And yes, it's a compile-time failure, which is great. My comment should not be read as criticism at all (though I would likely use `uint16_t`, as the OP says the code is intended to work with [presumably aligned] 16-bit words).