ARM Technical Support Knowledge Articles

POINTER STORAGE SIZE

Applies to: C51 C Compiler

Answer


Information in this article applies to:


QUESTION

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?

ANSWER

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.

MORE INFORMATION

SEE ALSO

Article last edited on: 2005-07-15 13:04:09

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential