A.1.5 Defining const constant pointer

The pointer is interpreted differently depending on the "const" specified location.

To assign the const section to the zconst section, specify #pragma section zconst. To assign the const section to the zconst23 section, specify #pragma section zconst23.

 

-

const char *p;

This indicates that the object (*p) indicated by the pointer cannot be rewritten.

The pointer itself (p) can be rewritten.

Therefore the state becomes as follows and the pointer itself is allocated to RAM (.data etc.).

*p = 0;     /*error*/
p = 0;      /*correct*/

 

-

char *const p;

This indicates that the pointer itself (p) cannot be rewritten.

The object (*p) indicated by the pointer can be rewritten.

Therefore the state becomes as follows and the pointer itself is allocated to ROM (.const/.zconst/.zconst23).

*p = 0;     /*correct*/
p = 0;      /*error*/

 

-

const char *const p;

This indicates that neither the pointer itself(p) nor the object (*p) indicated by the pointer can be rewritten.

Therefore the state becomes as follows and the pointer itself is allocated to ROM (.const/.zconst/.zconst23).

*p = 0;     /*error*/
p = 0;      /*error*/