3.6.1.5 Const-data-in-progmem Option

The -mconst-data-in-progmem option changes the location of where objects defined using just the const type qualifier are stored.

By default, all objects defined using just the const type qualifier are located in and accessed from program memory, and this action can be made explicit by using the -mconst-data-in-progmem option. Any pointer to a const-qualified object will be able to read both data and program memory and determine at runtime which space is to be accessed. See also 4.4.3 Objects in Program Space.

The -mno-const-data-in-progmem option forces all objects defined using just the const type qualifier to be copied to data memory, where they can be read using different instructions when required. Disabling this feature does not affect code built for devices that have flash mapped into data memory, for example the avrxmega3 and avrtiny architectures. Pointers to objects qualified with just const will always read from data memory, and alternatives to the string functions normally provided by <string.h> must be used to access strings that have been located in program memory.

The macro __AVR_CONST_DATA_IN_PROGMEM__ is defined if this feature is enabled and const-qualified objects are located in and accessed from program memory.

Having const-qualified objects in program memory will free up more valuable RAM and does not require the use of non-standard keywords, making it easier to have pointers access such objects. Accessing const-qualified objects in data memory is the more efficient in terms of program size.