I have a struct as follows.
struct A {
uint32_t a : 1;
uint32_t b : 1;
};
Is struct A guaranteed by the standard to have size 4? Is it possible that a compiler instead
uses only one byte for struct A since it uses exactly two bits?
struct B {
uint32_t a : 1;
uint32_t b : 1;
uint32_t c : 30;
} b;
If I would like to set the bitfields in b to zero, since sizeof(struct B) = 4, it looks good to me to do so by
*(uint32_t*)&b = 0. But I saw a lot of discussions on SO arguing that such a pointer cast is a bad practice. I wonder what makes *(uint32_t*)&b = 0 bad here and what I should do (I know I can use memset to reset the bitfields but I am interested in other portable ways).