c - Can bit-fields only be fields of a structure/union, never "normal", "stand-alone" variables? -


the field part of bit-fields seems suggest can fields inside structure or union.

can bit-field typical "stand-alone" variable, outside aggregate data-type union or structure follows:

   int sum:6;   //can work declaration statement?    sum=4; 

if not, why so? if bit-fields intended use less memory, why can't declare variable bit-field if know won't exceed size?

bit-fields part of structs or unions because that's c standard allows. have been possible decide differently. why committee decided write standard way is, have ask them.

to find information in c99 standard:

from table of contents:

6.7 declarations

6.7.2 type specifiers (okay, 1 little bit obscure)

6.7.2.1 structure , union specifiers.

one bit-field declarator_opt : constant-expression part of syntax. syntax allowed here, , consequence 1 cannot declare bit-fields elsewhere.

the syntax tells name of bit-field can optionally omitted, if curious sort of information. clause 6.7.2.1:3 goes further , prohibits names 0-length bit-fields.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -