ARM Technical Support Knowledge Articles

STATIC POINTERS VS EXPLICITLY PLACED VARIABLES

Applies to: C51 C Compiler

Answer


Information in this article applies to:


SYMPTOM

My project includes several peripherals mapped into XDATA space. I want to access the registers of these peripherals, and I've declared a series of static pointers to address them. For example:

xdata volatile unsigned char *pReg1 = 0x1234;

I also assigned these values to other pointers, like this:

xdata volatile unsigned char *regPtr = pReg1;

The optimizer can alter these pointers so that I cannot access these registers.

CAUSE

The optimizer recognizes the locations you specified as arbitrary and not necessary to be reserved. It re-assigns your "registers" to other locations to streamline program flow.

RESOLUTION

Instead of using static pointers you should declare a variable for each XDATA register location and force it to the proper address using the _at_ keyword. You can then use this address to create pointers. The following is an example of how this can be done.

xdata volatile unsigned char Reg1 _at_ 0x1234;
xdata volatile unsigned char *regPtr = &Reg1;

MORE INFORMATION

SEE ALSO

Article last edited on: 2005-07-15 10:10:24

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