r/cpp • u/meetingcpp Meeting C++ | C++ Evangelist • Jul 19 '26
A better bitset for enum flags
https://www.elbeno.com/blog/?p=1836
41
Upvotes
r/cpp • u/meetingcpp Meeting C++ | C++ Evangelist • Jul 19 '26
View all comments
Show parent comment
3
u/fdwr fdwr@github 🔍 Jul 20 '26
For your particular
structabove, I foresee no issues with {clang, gcc, msvc}, as they should yield identical results, since all the bitfields nicely align to the alignof of each base type (e.g. you don't have the: 2straddling across two bytes). The[[gnu::packed]]shouldn't even be needed, right? Of course, there's still the endianness consideration if you built with gcc on a BE8 architecture, which would flip all the bitfields around (sotype,system, anddescriptor_privilege_levelwould becomedescriptor_privilege_level,system, andtype🙃), but endianness is a bigger problem anyway as you'd have to deal with the non-bitfield fields too likeuint16_t segment_limit_low. The remaining sting is the niche compilers for weirder architectures, where saysizeof(char) == sizeof(int).