ARM Technical Support Knowledge Articles

PROBLEMS INITIALIZING ABSOLUTELY LOCATED VARIABLES

Applies to: C251 C Compiler

Answer


Information in this article applies to:


QUESTION

I declared two global variables in file main.c as follows:

unsigned char near x _at_ 0x2000 = 5;
unsigned char near y _at_ 0x3000 = 10;

In the file main.h, I wrote:

extern unsigned char near x;
extern unsigned char near y _at_ 0x3000;

main.h is included in main.c. On the map file generated, both x and y are not located at the desired locations. Why?

ANSWER

This only happens when you initialize a variable located with the _at_ keyword when declaring the variable and the extern is in the same scope as the declaration.

The solution is to arrange your project so that you do not have externs and declarations for the same variables in the same scope.

The best way to do this is:

  1. Create a file called globals.c which includes the declarations of all your global variables.
  2. Create a file called globals.h which includes all the externs for your global variables.
  3. Include the file globals.h in every source file except globals.c. Include globals.c in your project.

MORE INFORMATION

Article last edited on: 2005-07-15 12:54:01

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