9.8.1 Const Type Qualifier

The compiler supports the use of the ANSI type qualifiers const and volatile.

The const type qualifier is used to tell the compiler that an object is read only and will not be modified. If any attempt is made to modify an object declared const, the compiler will issue a warning or error.

User-defined objects declared const are placed, by default, in the program space and may be accessed via the program visibility space (see the 11.3 Variables in Program Space section). Usually a const object must be initialized when it is declared, as it cannot be assigned a value at any point at runtime. For example:

const int version = 3;

will define version as being an int variable that will be placed in the program memory, will always contain the value 3, and which can never be modified by the program.

The memory model -mconst-in-data will allocate const-qualified objects in data space, which may be writable.