Keil™, An ARM® Company

Cx51 User's Guide

USERCLASS Compiler Directive

Abbreviation UCL
Arguments 

(Memory Space = user_classname)

Memory Space refers to the default memory space used for variables
or program code and is explained below:

Memory
Space
Description
CODEProgram code.
ECODEProgram code (for extended devices).
CONSTVariables in code space (CONST class).
XCONSTConstants in const xdata space (XDATA class).
XDATAVariables in xdata space (XDATA class).
HDATAVariables in extended far space (HDATA class).
HCONSTConstants in extended const far space (HCONST class).

user_classname is the name for a memory class.
You may supply any valid identifier for a class name.

Default Segments receive the default class name.
µVision Options — C51 — Misc controls.
Description 

The USERCLASS directive assigns a user defined class name to a compiler generated segment. By default, the C51 Compiler uses the basic class name for segment definitions.

The user class name may located at a specific address range by the extended LX51 Linker. This allows you to locate all segments with a class name such as XDATA_FLASH to a specific memory area.

The USERCLASS directive renames the basic class name for an entire module. Overlayable segments (typically local variables in C functions) are not renamed. To rename a local variable, you must change its allocation type to static by including the static keyword in the variable definition. For example:

/* Rename XDATA class to XDATA_MyClass */
#pragma userclass (xdata = MyClass)

xdata int glob_var;          /* Stored in XDATA_MyClass */
static xdata int static_var; /* Stored in XDATA_MyClass */

void func (void)
{
static xdata long func_var;  /* Stored in XDATA_MyClass */
xdata long func_var2;        /* Stored in XDATA */

func_var = 1;
func_var2 = 2;
}

void main (void)
{
static xdata long main_var;  /* Stored in XDATA_MyClass */
xdata long main_var2;        /* Stored in XDATA */

main_var = 1;
main_var2 = 2;

func ();

while (1);
}

Memory classes are only available when you use the OMF2 format and the extended LX51 Linker/Locater.

Example 
C51 UCL.C

#pragma userclass (xdata = flash)
#pragma userclass (hconst = patch)

int xdata x1 [10];                // XDATA_FLASH
const char far tst[] = "Hello";   // HCONST_PATCH