Bit fields in C:Syntax, Uses, advantages, limitations

To access a bit, C has a built in feature known as bit fields. It is declared as an integral or enumeration type. A bit filed having one bite is declared as unsigned.

Syntax of bit fields:

struct struct_type_name {

type name1 : number_of_bits;

type name2 : number_of_bits;



type nameN : number_of_bits;

} variable_list;

Uses and advantages of bit fields:

1) When storage is less, many true false variables can be stored in one byte.

2) There are some encryption routines which have to access the bits within a byte.

3) There are some devices that transmit status info encoded in bits.

4) It adds more efficiency to the program.

5) For analyzing input from a hardware.

Limitations of Bit fields:

1) Address of a bit field cannot be taken in to account.

2) We can’t have an array of but fields.

3) A bit field can’t be declared as static.

4) A bit filed is dependent on a machine.

Leave a Reply