Example
- Arrays of bit-fields, pointers to bit-fields and functions returning bit-fields are not allowed.
- The address operator (&) cannot be applied to bit-field members.
- The data type of a bit-field must be wide enough to contain the size of the field.
- The
sizeof()
operator cannot be applied to a bit-field.
- There is no way to create a
typedef
for a bit-field in isolation (though you can certainly create a typedef
for a structure containing bit-fields).
typedef struct mybitfield
{
unsigned char c1 : 20; /* incorrect, see point 3 */
unsigned char c2 : 4; /* correct */
unsigned char c3 : 1;
unsigned int x[10]: 5; /* incorrect, see point 1 */
} A;
int SomeFunction(void)
{
// Somewhere in the code
A a = { … };
printf("Address of a.c2 is %p\n", &a.c2); /* incorrect, see point 2 */
printf("Size of a.c2 is %zu\n", sizeof(a.c2)); /* incorrect, see point 4 */
}