I need to use a 6-byte (48-bit) bitfield in a structure that I can use as unsigned integer for comparison etc. Something along the following:
pack (1)
struct my_struct {
_int64 var1:48;
} s;
if (s.var >= 0xaabbccddee) { // do something }
But somehow on 64-bit Windows, sizeof this struct always returns 8 bytes instead of 6 bytes. Any pointers are appreciated?
Unfortunately, a bit filed have the size of the underlying type, in this case an _int64 is 8 bytes.
As there is no six byte integers in any compiler that I know of, you would have to find a better way. One is to use one 16 and one 32 bit value (or three 16 bit values) and write your own comparison function.
For example:
As a bonus you don't need
#pragma pack, which brings a lot of other problems.