#pragma CONST_SEG: Constant Data Segment Definition

Scope

Until the next CONST_SEG pragma

Syntax
#pragma CONST_SEG (<Modif>  <Name>|DEFAULT) 
Synonym

CONST_SECTION

Arguments
Listing: Some strings which may be used for <Modif>


 __FAR_SEG    (compatibility alias: FAR) __PAGED_SEG 
Note: Do not use a compatibility alias in new code. It only exists for backwards compatibility. Some of the compatibility alias names conflict with defines found in certain header files. Therefore, using them can cause hard to detect problems. Avoid using compatibility alias names.

The segment modifiers are backend-dependent. The __FAR_SEG and __PAGED_SEG modifier specifies a segment which is accessed with 16-bit addresses (RS08 addresses use up to 14 bits). The difference between the two is that objects defined in a segment marked by __PAGED_SEG are assumed not to cross page boundary. It is the user's responsibility to ensure this.

<Name>: The name of the segment. This name must be used in the link parameter file on the left side of the assignment in the PLACEMENT part. For more information, refer to the Linker section in Build Tools Utilities manual.

Default

DEFAULT

Description

This pragma allocates constant variables into a segment. The segment is then allocated in the link parameter file to specific addresses. The CONST_SEG pragma sets the current const segment. All constant data declarations are placed in this segment. The default segment is set with:

#pragma CONST_SEG DEFAULT 

With the -Cc option set, constants are always allocated in constant segments in the ELF object-file format and after the first #pragma CONST_SEG (see -Cc: Allocate Const Objects into ROM).

The CONST_SEG pragma also affects constant data declarations as well as definitions. Ensure that all constant data declarations and definitions are in the same const segment.

Some compiler optimizations assume that objects having the same segment are placed together. Backends supporting banked data, for example, may set the page register only once for two accesses to two different variables in the same segment. This is also the case for the DEFAULT segment. When using a paged access to variables, place one segment on one page in the link parameter file.

When #pragma INTO_ROM: Put Next Variable Definition into ROM is active, the current const segment is not used.

The CONST_SECTION synonym has exactly the same meaning as CONST_SEG.

Examples

The following listing shows code that uses the CONST_SEG pragma.

Listing: Examples of the CONST_SEG pragma


/* Use the pragmas in a header file */ #pragma CONST_SEG __SHORT_SEG SHORT_CONST_MEMORY 
extern const int i_short; 
#pragma CONST_SEG CUSTOM_CONST_MEMORY 
extern const int j_custom; 
#pragma CONST_SEG DEFAULT 
/* Some C file, which includes the above header file code */ 
void main(void) { 
  int k = i; /* may use short access */ 
  k= j; 
} 
/* in the C file defining the constants : */ 
#pragma CONST_SEG __SHORT_SEG SHORT_CONST_MEMORY 
extern const int i_short=7 
#pragma CONST_SEG CUSTOM_CONST_MEMORY 
extern const int j_custom=8; 
#pragma CONST_SEG DEFAULT 

The following listing shows code that uses the CONST_SEG pragma improperly.

Listing: Improper use of the CONST_SEG pragma


#pragma DATA_SEG CONST1 #pragma CONST_SEG CONST1 /* error: same segment name has different 
                            types!*/ 
#pragma CONST_SEG C2 
#pragma CONST_SEG __SHORT_SEG C2 // error: segment name has modifiers! 
#pragma CONST_SEG CONST1 
extern int i; 
#pragma CONST_SEG DEFAULT 
int i; /* error: i is declared in different segments */ 
#pragma CONST_SEG __SHORT_SEG DEFAULT /* error: no modifiers for the 
                                         DEFAULT segment are allowed 
See also

RS08 Backend

Linker section of the Build Tools manual

#pragma DATA_SEG: Data Segment Definition

#pragma STRING_SEG: String Segment Definition

#pragma INTO_ROM: Put Next Variable Definition into ROM

-Cc: Allocate Const Objects into ROM