Microchip Technology SW006023-3N Ficha De Dados

Página de 238
Supported Data Types and Variables
 2012 Microchip Technology Inc.
DS51686E-page 99
Unnamed bit fields may be declared to pad out unused space between active bits in 
control registers. For example, if dummy is never referenced, the structure above could 
have been declared as:
struct {
        unsigned        lo : 1; 
        unsigned           : 6; 
        unsigned        hi : 1; 
} foo;
A structure with bit fields may be initialized by supplying a comma-separated list of ini-
tial values for each field. For example:
struct {
        unsigned        lo  : 1; 
        unsigned        mid : 6; 
        unsigned        hi  : 1; 
} foo = {1, 8, 0};
Structures with unnamed bit fields may be initialized. No initial value should be supplied 
for the unnamed members, for example:
struct {
        unsigned        lo  : 1; 
        unsigned            : 6; 
        unsigned        hi  : 1; 
} foo = {1, 0}; 
will initialize the members lo and hi correctly.
The MPLAB XC compiler supports anonymous unions. These are unions with no iden-
tifier and whose members can be accessed without referencing the enclosing union. 
These unions can be used when placing inside structures. For example:
struct {
union {
int x;
double y;
};
} aaa;
int main(void)
{
aaa.x = 99;
// ...}
Here, the union is not named and its members accessed as if they are part of the struc-
ture. Anonymous unions are not part of any C Standard and so their use limits the por-
tability of any code.