CONST_SEG

Sets the current constant data segment.

Syntax
  #pragma CONST_SEG <name>|DEFAULT  
Parameters

<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

DEFAULT

Remarks

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.

Note: The CONST_SEG pragma affects constant data definitions as well as declarations. Ensure that, for a given constant variable, all declarations and the definition are in the same segment.

The following listing exemplifies the correct usage of the CONST_SEG pragma:

Listing: Using pragma CONST_SEG
/* 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:

Listing: Improper Usage of CONST_SEG pragma
#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 **/