5.3.5.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 };  // record place in program memory

In this case, the entire structure will be placed into the program space and 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 read-only. Compare the following structure with the above.

struct {
    const int number;
    int * const ptr;
} record = { 0x55, &i };  // record placed in data memory