+91 9945200008     support@uttaracomputers.com
LOGIN     REGISTER    

Bit Fields

Answered
0
0

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

  • You must to post comments
Best Answer
1
0

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

  • cks3976@rediffmail.com
    |  B1   | B2    | B3     | B4     | B5     | B6     | B7     | B8     | B9     | B10     | B11     | B12  | |dd mm | PAD | PAD | B5 | B6 | B7 | B8 | Understood Sir. Thank you !!
  • You must to post comments
0
0

|  B1   | B2    | B3     | B4     | B5     | B6     | B7     | B8     | B9     | B10     | B11     | B12  |

|dd mm | PAD | PAD | B5 | B6 | B7 | B8 |

Understood Sir. Thank you !!

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.