Keil Logo

C51: Initializing an Absolutely Located Variable


Information in this article applies to:

  • C51 version 5.50 and later

QUESTION

I have declared a global variable using:

unsigned char xdata foo _at_ 0x2000 = 5;

However, upon compilation I get the following error:

Error 274: 'foo': absolute specifier illegal

How can I initialize an absolutely located variable?

ANSWER

You cannot both specify a location for a variable and initialize it at the same time. The best solution is to initialize the variable separately in an initialization routine. For example:

void init_globals(void)
{
  foo = 5;
}

which is then called from the main function.

MORE INFORMATION

SEE ALSO


Last Reviewed: Thursday, February 25, 2021


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.