Table of Contents        Previous topic       Next topic       

C COMPILER->8051 Specific Features->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 qualifierAssociated memory space
_codeprogram memory
_datainternal data memory
_bdatainternal bit addressable data memory
_idatainternal indirectly addressable data memory
_xdataexternal data memory
_genericall memory spaces

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

(The keywords _bit, _sbit, _sfr and _sfr16 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.  If this is what is required, then the structure or union should be debated as a typedef.  Each object created with the typedef can then be different.  For example:

typedef struct {
    Char _idata ** ppszName;
    Char ** ppszAddress;
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.