struct foo { unsigned x:1; } f;
printf("%d\n", (int)sizeof(f.x = 1));
What is the expected result and why? The use of the lvalue bit field size is not allowed. But using the assignment operator, it seems that we can still take the size of the bit field type.
What is the size of the bit field in bytes? Is this the size of the storage unit in which the bitfield is located? Is this the number of bits occupied by the bf counter, rounded to the nearest byte?
Or is the constructor behavior undefined because there is nothing in the standard that answers the above questions? Several compilers on the same platform give me inconsistent results.
gnu
source
share