10.4 Variables in Program Memory
To have objects placed into program memory, which is Flash memory on most target devices, they should be qualified
const
and additionally use the space(prog)
attribute, for example:const int __attribute__((space(prog))) const_symbol;
This combination places the object const_symbol
into a .text
section rather than a .rodata
section. You still need to use the space(prog)
attribute even if you are also using a section()
attribute. Failure to use the const
specifier with the space(prog)
attribute will result in a compilation error: space("prog") object 'symbol' should be const qualified
.Without the space(prog)
attribute, some options can affect where objects only qualified with const
are located, so both the attribute and qualifier should be used to ensure the objects are located in program memory. (See also 9.9.1 Const Type Qualifier.)