News for hackers. Stuff that matters.
Re:Type-safe Bitmasks in C++ by Animats on Wednesday June 13, 2018 @03:09PM (#17306079)
Portability is a problem. There is this:

Microsoft Specific

The ordering of data declared as bit fields is from low to high bit.

END Microsoft Specific[1]

In practice, everybody does it that way.

For fields only one byte wide, this isn't an issue for major compilers. NTP has been using this for decades without problems. But for structs more than one byte wide, there are little-endian/big endian problems. Just like with the numeric types.

This is only an issue if you intend to write the bitfield to a network, file, or device. Locally, you usually don't care about the representation.

[1] https://docs.microsoft.com/en-gb/cpp/cpp/cpp-bit-fields

There are no comments on this comment yet.