Microchip Technology SW006022-2 데이터 시트

다운로드
페이지 338
Supported Data Types and Variables
 2012 Microchip Technology Inc.
DS52071B-page 97
struct foo
 will have a size of 10 bytes using the compiler. i will be allocated at bit 
offset 0 (through 39). There will be 8 bits of padding before j, allocated at bit offset 48. 
If j were allocated at the next available bit offset, 40, it would cross a storage boundary 
for a 16 bit integer. k will be allocated after j, at bit offset 64. The structure will contain 
8 bits of padding at the end to maintain the required alignment in the case of an array. 
The alignment is 2 bytes because the largest alignment in the structure is 2 bytes.
struct bar
 will have a size of 8 bytes using the compiler. I will be allocated at bit 
offset 0 (through 39). There is no need to pad before J because it will not cross a 
storage boundary for a char. J is allocated at bit offset 40. K can be allocated starting 
at bit offset 48, completing the structure without wasting any space.
Unnamed bit-fields may be declared to pad out unused space between active bits in 
control registers. For example:
    struct foo {
      unsigned lo : 1;
      unsigned    : 6;
      unsigned hi : 1;
    } x;
A structure with bit-fields may be initialized by supplying a comma-separated list of ini-
tial values for each field. For example:
    struct foo {
      unsigned lo  : 1;
      unsigned mid : 6;
      unsigned hi  : 1;
    } x = {1, 8, 0};
Structures with unnamed bit fields may be initialized. No initial value should be supplied 
for the unnamed members, for example:
    struct foo {
      unsigned lo  : 1; 
      unsigned     : 6; 
      unsigned hi  : 1; 
    } x = {1, 0}; 
will initialize the members lo and hi correctly.