Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 User Manual

Product codes
SW006021-1
Page of 518
C Language Features
 2012 Microchip Technology Inc.
DS52053B-page 149
5.4.4
Structures and Unions
MPLAB XC8 C Compiler supports struct and union types. Structures and unions 
only differ in the memory offset applied to each member.
These types will be at least 1 byte wide. The members of structures and unions may 
not be objects of type bit, but bit-fields are fully supported.
Structures and unions may be passed freely as function arguments and function return 
values. Pointers to structures and unions are fully supported.
5.4.4.1
STRUCTURE AND UNION QUALIFIERS
The compiler supports the use of type qualifiers on structures. When a qualifier is 
applied to a structure, all of its members will inherit this qualification. In the following 
example the structure is qualified const.
const struct {
        int number;
        int *ptr;
} record = { 0x55, &i };
In this case, the entire structure will be placed into the program space and each mem-
ber will be read-only. Remember that all members are usually initialized if a structure 
is const as they cannot be initialized at runtime.
If the members of the structure were individually qualified const, but the structure was 
not, then the structure would be positioned into RAM, but each member would be 
read-only. Compare the following structure with the above.
struct {
        const int number;
        int * const ptr;
} record = { 0x55, &i };