DATA_SEG

Sets the current data segment.

Syntax
  #pragma DATA_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 data segment: either the default data segment (that is, DEFAULT_RAM), or a user-defined segment. All the variables subsequently declared are allocated into that segment by the linker.

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

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

Listing: Using pragma DATA_SEG
/* p.h */
#pragma DATA_SEG MY_RAM

extern int x;

#pragma DATA_SEG DEFAULT

extern int y;

/* p.c */

#pragma DATA_SEG MY_RAM

int x;

#pragma DATA_SEG DEFAULT

int y;

/* main.c */

#include "p.h"

void main(void) 

{

x = 5;

y = 10;

}

The following listing contains examples of improper DATA_SEG pragma usage:

Listing: Improper Usage of DATA_SEG pragma
#pragma CONST_SEG MY_RAM
#pragma DATA_SEG  MY_RAM

/** incorrect: the same segment name used with different segment types 
**/

#pragma DATA_SEG MY_RAM

extern int x;

#pragma DATA_SEG DEFAULT

extern int x;

/** incorrect: variable 'x' is declared in two different segments **/

/* p.h */

#pragma DATA_SEG MY_RAM

extern int x;

#pragma DATA_SEG DEFAULT

extern int y;

#pragma DATA_SEG MY_RAM

extern int z;

#pragma DATA_SEG DEFAULT

/* p.c */

#pragma DATA_SEG MY_RAM

int x;

#pragma DATA_SEG DEFAULT

int y, z;

/** incorrect: variable 'z' is declared in segment MY_RAM and defined 
in segment DEFAULT **/