c++ - sizeof packed bitfield returns 4 but I expect 1. How does it come and how I can fix? -
i have bitfield defined follows (where expect of size: 1):
#pragma pack(push, 1) typedef struct { unsigned boolfoo : 1; unsigned placeholder : 7; } knownbitflags1_t; #pragma pack(pop)
but after painfull debugging figgured out sizeof(knownbitflags1)
returns 4
why?
i tried:
typedef struct { unsigned boolfoo : 1; unsigned placeholder : 7; } __attribute__((packed, aligned(1))) knownbitflags1_t;
what keeps sizeof structure @ 4 anyway.
so can stop padding array of structure?
it depends on underlying type. change unsigned
unsigned char
:
typedef struct { unsigned char boolfoo : 1; unsigned char placeholder : 7; } knownbitflags1_t;
Comments
Post a Comment