Technical Support

C51: INITIALIZING AN ABSOLUTELY LOCATED VARIABLE


Information in this article applies to:

  • C51 Version 5.50

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 seperately in an intitialization routine. For example:

void init_globals(void)
{
  foo = 5;
}

which is then called from the main function.

MORE INFORMATION

SEE ALSO

FORUM THREADS

The following Discussion Forum threads may provide information related to this topic.

Last Reviewed: Friday, July 15, 2005


Did this article provide the answer you needed?
 
Yes
No
Not Sure