Home     Blog    News    Ask a Question    Contact

Memory Space Qualifiers

Memory space qualifiers are used to place global objects in specific memory spaces or to declare a pointer as pointing to a particular memory space. The following table represents the memory space qualifiers supported by the Crossware 8051 ANSI C compiler and the memory space with which they are associated:

Memory space qualifier Associated memory space
_code program memory
_data internal data memory
_bdata internal bit addressable data memory
_idata internal indirectly addressable data memory
_xdata external data memory
_generic all memory spaces

The use of a memory space qualifier overrides the default that would otherwise be used by the compiler.

(The keywords _bit, _sfrbit, _sfr and _sfrword are also supported but they are types rather than memory space qualifiers).

Memory space qualifiers are placed to the left of the item being qualified.

Qualifying a Object

To specify location of the object itself, the qualifier is placed immediately to the left of the variable name separated by white space. For example:

int _data nCount;

char * _xdata pszText;

struct tagCapture _idata sCapture;

In the above examples:

Only the contents of a pointer can be generic and so the _generic qualifier should not be used on the object itself.

Local objects and function parameter objects are always placed in the default memory space location and so should not be qualified.

Qualifying the Contents of a Pointer

To qualifier the contents of a pointer, the qualifier is placed to the immediate left of the *' symbol (optionally separated by white space).

For example:

char _idata * pszText;

char _xdata * _idata * ppszMessage;

struct tagInfo{
    char _idata ** ppszName;

In the above examples:

Both ppszName and ppszAddress have not been fully defined. The compiler will determine an appropriate pointer type for the uncommitted parts of the declaration.

Note, however, that the compiler can only make a single choice for each uncommitted pointer. It is not possible for a pointer in a structure or union to be one type when the tag is used with one object and another type when the tag is used with a different object. It this is what is required, then the structure or union should be declared as a typedef. Each object created with the typedef can then be different. For example:

typedef struct {
    char _idata ** ppszName;

INFO Info1;

INFO Info2;

Pointers Info1.ppszAddress and Info2.ppszAddress can be different pointer types.

In general it should not be necessary to qualify the contents of a pointer. The smart pointer technology incorporated into the compiler will normally determine the appropriate pointer types.