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:

  • Two bytes of internal data memory are reserved for integer nCount
  • One, two or three bytes of external data memory are reserved for pointer pszText. (pszText is a uncommitted pointer and the compiler will decide what it points to and how many bytes of storage are required depending upon how the pointer is used).
  • Memory in indirectly addressable data memory is reserved for structure sCapture. (The number of bytes reserved matches the size of the structure).

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;
char**ppszAddress;
};

In the above examples:

  • pszText is located in the default memory space and is a one byte pointer pointing to a one byte character located in indirectly addressable internal data memory.
  • ppszMessage is located in the default memory space and is a one byte pointer pointing to a two byte pointer in indirectly addressable internal data memory which points to a one byte character located in external data memory.
  • ppszName will be located in the memory space of the object that has used structure tagInfo. It is a one, two or three byte pointer, pointing at a one byte pointer which points to a one byte character in indirectly addressable internal data memory.
  • ppszAddress will be located in the same memory space as ppszName which can vary depending on the object that has used the tagInfo structure. It is a one, two or three byte pointer which points to a one, two or three byte pointer which points to a one byte character.

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;
char**ppszAddress;
} INFO;

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.


|Home|Request information|How to order|


Crossware Products
Old Post House, Silver Street,
Litlington, Royston, Herts,
SG8 0QE, United Kingdom
Tel: + 44 (0) 1763 853 500,
Fax: + 44 (0) 1763 853 330

Copyright © 1996-2004 Crossware Products. All rights reserved.

CROSSWARE and the Crossware logo are trademarks of Crossware Products.