User`s manual

198 digi.com Keywords
const
This keyword declares that a value will be stored in flash, thus making it unavailable for modification.
const is a type qualifier and may be used with any static or global type specifier (char, int, struct,
etc.). The const qualifier appears before the type unless it is modifying a pointer. When modifying a
pointer, the const keyword appears after the “*.”
In each of the following examples, if const was missing the compiler would generate a trivial warning.
Warnings for const can be turned off by changing the compiler options to report serious warnings only.
The use of const is not currently permitted with return types, auto variables or parameters in a function
prototype.
Example 1:
Example 2:
Example 3:
Example 4:
Example 5:
NOTE: The default storage class is auto, so the above code would have to be outside of a
function or would have to be explicitly set to static.
// ptr_to_x is a constant pointer to an integer
int x;
int * const cptr_to_x = &x;
// cptr_to_i is a constant pointer to a constant integer
const int i = 3;
const int * const cptr_to_i = &i;
// ax is a constant 2 dimensional integer array
const int ax[2][2] = {{2,3}, {1,2}};
struct rec {
int a;
char b[10];
};
// zed is a constant struct
const struct rec zed = {5, “abc”};
// cptr is a constant pointer to an integer
typedef int * ptr_to_int;
const ptr_to_int cptr = &i;
// this declaration is equivalent to the previous one
int * const cptr = &i;