11.3.2 Automatically Allocating Objects into Program Space

When the option -mconst-in-code is enabled, const-qualified variables that are not auto are placed in program memory. Any auto variables qualified const are placed on the stack along with other auto variables.

Any const-qualified (auto or non-auto) variable will always be read-only and any attempt to write to these in your source code will result in an error being issued by the compiler.

A const object is usually defined with initial values, as the program cannot write to these objects at runtime. However this is not a requirement. An uninitialized const object is allocated space along with other uninitialized RAM variables, but is still read-only. Here are examples of const object definitions.

const char IOtype = ’A’; // initialized const object

const char buffer[10]; // I reserve memory in RAM

See the 17 Mixing C and Assembly Code section for the equivalent assembly symbols that are used to represent const-qualified variables in program memory.