Keil Logo

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
CODE Program code.
ECODE Program code (for extended devices).
CONST Variables in code space (CONST class).
XCONST Constants in const xdata space (XDATA class).
XDATA Variables in xdata space (XDATA class).
HDATA Variables in extended far space (HDATA class).
HCONST Constants 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
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.