3 ms·
It certainly doesn't help that the "wrong" way is featured in almost every textbook, tutorial and article I've seen in the last 15 years. Your example is actua
by alxlaz 6y ago
It certainly doesn't help that the "wrong" way is featured in almost every textbook, tutorial and article I've seen in the last 15 years.
Your example is actually for the most favourable case because there are native 32-bit types. I've seen countless attempts to implement three-byte records via custom Uint24 classes that overload operators and abstract endianness (in various buggy ways) instead of just reading three damn bytes in a uint32_t. Supposedly in the name of readability ("I want to be explicit that this stores a 24-bit variable, not a 32-bit variable, so I'm going to copy-paste these 200 lines of either template magic or line noise, I'm not sure, but see how readable it is now? Oh yeah it's still 32-bit underneath, yeah, I'm not sure what happens if you write a 32-bit variable there, I think it breaks. This is way better than a typedef though, 'cause, uh, C++-17?)