next up previous contents index
Next: 3.5 Parameters & Local Up: 3. Using SDCC Previous: 3.3 MCS51/DS390 Storage Class   Contents   Index

3.4 Pointers

SDCC allows (via language extensions) pointers to explicitly point to any of the memory spaces of the 8051. In addition to the explicit pointers, the compiler also allows a _generic class of pointers which can be used to point to any of the memory spaces.

Pointer declaration examples:

/* pointer physically in xternal ram pointing to object in internal ram */  
data unsigned char * xdata p; 
 
/* pointer physically in code rom pointing to data in xdata space */  
xdata unsigned char * code p; 
 
/* pointer physically in code space pointing to data in code space */  
code unsigned char * code p; 
 
/* the folowing is a generic pointer physically located in xdata space */ 
char * xdata p;

Well you get the idea.

For compatibility with the previous version of the compiler, the following syntax for pointer declaration is still supported but will disappear int the near future.

unsigned char _xdata *ucxdp; /* pointer to data in external ram */  
unsigned char _data  *ucdp ; /* pointer to data in internal ram */  
unsigned char _code  *uccp ; /* pointer to data in R/O code space */ 
unsigned char _idata *uccp;  /* pointer to upper 128 bytes of ram */

All unqualified pointers are treated as 3-byte (4-byte for the ds390) generic pointers. These type of pointers can also to be explicitly declared.

unsigned char _generic *ucgp;

The highest order byte of the generic pointers contains the data space information. Assembler support routines are called whenever data is stored or retrieved using generic pointers. These are useful for developing reusable library routines. Explicitly specifying the pointer type will generate the most efficient code. Pointers declared using a mixture of OLD and NEW style could have unpredictable results.


next up previous contents index
Next: 3.5 Parameters & Local Up: 3. Using SDCC Previous: 3.3 MCS51/DS390 Storage Class   Contents   Index
Johan Knol
2001-07-13