In the following Structure definition,
typedef struct date
int dd : 5 ; // Bit field map to 5 bits
int mm : 4 ; // Bit field map to 4 bits
int yy ; // Default size of 4 Bytes
} date ;
printf( “%ld \n”, sizeof( date ) ) ;
I was thinking the result should be ( 5 + 4 + 32 ) bits = 41 bits ~ 6 Bytes. But the result of the program is 8 Bytes. Where are the additional 2 Bytes getting added to the Structure ?
The consecutive bit fields are added ( 4 + 5 = 9 bits ) and padded to the size of the data type ( in this case, “int”; i.e. 4 bytes ). Hence the size of the structure is 8 bytes.
Please login first to submit.