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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -