Dear Sir,
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 ?
>> 8
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.
MLS Shastry
| B1 | B2 | B3 | B4 | B5 | B6 | B7 | B8 | B9 | B10 | B11 | B12 |
|dd mm | PAD | PAD | B5 | B6 | B7 | B8 |
Understood Sir. Thank you !!
Please login first to submit.