foralex / picoc

Automatically exported from code.google.com/p/picoc
0 stars 0 forks source link

Bit-Field support request #147

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Usually, a struct-declarator is just a declarator for a member of a structure 
or union. A structure member may also consist of a specified number of bits. 
Such a member is also called a bit-field; its length is set off from the 
declarator for the field name by a colon.
     struct-declarator:
           declarator declaratoropt : constant-expression

This is the declaration that actually is not handled:

  #pragma pack(1)
  typedef union _byteBool {
      struct {
            unsigned int b0:1;
            unsigned int b1:1;
            unsigned int b2:1;
            unsigned int b3:1;
            unsigned int b4:1;
            unsigned int b5:1;
            unsigned int b6:1;
            unsigned int b7:1;
      } bit;
      unsigned char val;
  } byteBool;

source http://en.wikipedia.org/wiki/C_syntax

Bit fields
C also provides a special type of structure member known as a bit field, which 
is an integer with an explicitly specified number of bits. A bit field is 
declared as a structure member of type int, signed int, unsigned int, or _Bool, 
following the member name by a colon (:) and the number of bits it should 
occupy. The total number of bits in a single bit field must not exceed the 
total number of bits in its declared type.

As a special exception to the usual C syntax rules, it is 
implementation-defined whether a bit field declared as type int, without 
specifying signed or unsigned, is signed or unsigned. Thus, it is recommended 
to explicitly specify signed or unsigned on all structure members for 
portability.

Empty entries consisting of just a colon followed by a number of bits are also 
allowed; these indicate padding.

The members of bit fields do not have addresses, and as such cannot be used 
with the address-of (&) unary operator. The sizeof operator may not be applied 
to bit fields.

The following declaration declares a new structure type known as f and an 
instance of it known as g. Comments provide a description of each of the 
members:

Original issue reported on code.google.com by ozlbi...@gmail.com on 31 Jan 2012 at 7:10