Sets the current constant data segment.
#pragma CONST_SEG <name>|DEFAULT
<name>
The name of the data segment being defined. This segment must be explicitly allocated within the PLACEMENT block in the link parameter file. For more information, refer to the chapter Linker Issues of the Build Tools Utilities reference manual.
DEFAULT
This pragma sets the current constant data segment: either the default constant data segment (that is, ROM_VAR), or a user-defined segment. All the <keyword>const</keyword> variables subsequently declared are allocated into that segment by the linker.
The following listing exemplifies the correct usage of the CONST_SEG pragma:
/* p.h */ #pragma CONST_SEG MY_ROM extern const int cx; #pragma CONST_SEG DEFAULT extern const int y; /* p.c */ #pragma CONST_SEG MY_RAM const int cx = 1; #pragma CONST_SEG DEFAULT const int cy = 2; /* main.c */ #include "p.h" void main(void) { s = cx + cy; }
The following listing shows the examples of improper CONST_SEG pragma usage:
#pragma CONST_SEG MY_ROM #pragma CODE_SEG MY_ROM /** incorrect: the same segment name used with different segment types **/ #pragma CONST_SEG MY_ROM extern const int cx; #pragma CONST_SEG DEFAULT extern const int cx; /** incorrect: constant variable 'cx' is declared in two different segments **/ /* p.h */ #pragma CONST_SEG MY_ROM extern const int cx; #pragma CONST_SEG DEFAULT extern const int cy; #pragma CONST_SEG MY_ROM extern const int cz; #pragma CONST_SEG DEFAULT /* p.c */ #pragma CONST_SEG MY_ROM const int cx = 1; #pragma CONST_SEG DEFAULT const int cy = 2; const int cz = 3; /** incorrect: constant variable 'cz' is declared in segment MY_RAM and defined in segment DEFAULT **/