Keil Logo

C51: LOCATING VARIABLES TO FAR CONST SPACE


Information in this article applies to:

  • C51 Version 7
  • CX51 Version 7

QUESTION

I need to write portable code for my programs and I am using a header file that defines the memory types for the program in a generic way.

For example to put a constant into ROM I have used the syntax:

_code_ unsigned char MyConst = {0xAC};

With #define _code_ code the resulting syntax is:

code unsigned char MyConst = {0xAC};

Everything works fine this way, but now I want to put the constants into the far const space. However the definition #define _code_ const far results in syntax errors. What can I do?

Note that I do not want to use the following syntax, since I need to have portable code that works on several platforms:

unsigned char const far MyConst = {0xAC};

ANSWER

The correct syntax is #define _code_ far const which results in:

far const unsigned char MyConst = {0xAC};

This compiles fine with the CX51 Compiler or with the C51 Compiler when you use the OMF2 Directive.

MORE INFORMATION

  • Refer to Far Memory in the Cx51 User's Guide.
  • Refer to STRING in the Cx51 User's Guide.

SEE ALSO

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.