Machine-translated by Google. Questions are authored in English.
Top

Discussion

If the declaration unsigned c:5; is replaced by unsigned : 6; then

  • A.it results in a syntax error
  • B.it is meaningless
  • C.compiler will give a new name for the field
  • D.none of these

Answer: C

Correct answer: compiler will give a new name for the field

A bit-field declared without a name - unsigned : 6; - is an unnamed bit-field, which is legal C. It reserves the stated number of bits as padding but provides no name by which they can be accessed.

Its purpose is layout control: unnamed fields are used to align the following members at a particular bit position when a structure is mapped onto a hardware register or a defined external format. A width of zero has a further special meaning, forcing the next field to begin at the next storage unit.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.