|ARM Technical Support Knowledge Articles|
Applies to: C51 C Compiler
Information in this article applies to:
I have defined a pointer which points to a variable in XDATA memory. Why does the pointer takes up three bytes of memory, surely only two bytes are required?
You are using a generic pointer. Generic pointers may point to any memory space (IDATA, XDATA, CODE, etc.). For example:
unsigned char xdata foo; unsigned char *foo_ptr = &foo;
The first byte of the pointer indicates the type of memory the pointer points to. For example 01H is xdata. The remaining two bytes are of course the address.
You may declare memory-specific pointers instead of generic pointers if you want more efficient pointer operations. When declaring the pointer, include the memory area it points to. In the case of a pointer to XDATA, only two bytes are required for storage. For example:
unsigned char xdata foo; unsigned char xdata *foo_ptr = &foo;
The code generated by using a memory-specific pointer is smaller and faster than a generic pointer, however, the generic pointer may reference any memory area.
Both memory-specific pointers and generic pointers may be stored in any memory area.
Article last edited on: 2005-07-15 13:04:09
Did you find this article helpful? Yes No
How can we improve this article?