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 (excluding autos and parameters) declared
const
are placed in a special psect linked into the program space.
Objects qualified const
can be absolute. The
__at(address)
construct is used to place the object at the
specified address in program memory, as in the following example which places the object
tableDef
at address 0x100.
const int tableDef[] __at(0x100) = { 0, 1, 2, 3, 4};
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 a read-only int variable,
holding the value 3. However, uninitialized absolute extern const
objects
can be defined and are useful if you need to place an object in program memory over the top
of other objects at a particular location, as in the following example.
extern const char checksumRange[0x100] __at(0x800);
will define checksumRange
as an array of 0x100 characters
located at address 0x800 in program memory. This definition will not place any data in the
HEX file.