Keil Logo

C251: PROBLEMS INITIALIZING ABSOLUTELY LOCATED VARIABLES


Information in this article applies to:

  • C251 Version 2.14

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

Last Reviewed: Friday, July 15, 2005


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.