10.5.1 Structure and Union Qualifiers
The MPLAB XC16 C 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 foo {
int number;
int *ptr;
} record = { 0x55, &i };
In this case, the entire structure may be placed into the program space
where each member 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 still be read-only. Compare the following
structure with the one above.
struct {
const int number;
int * const ptr;
} record = { 0x55, &i};