Keil Logo

C51: Address Space Overflow With Far Constant


Information in this article applies to:

  • C51, version 7
  • CX51, version 7

QUESTION

I need many constants in my project, and for this reason, I initialize them as follows (This is just an example, the real initialization is a lot more complex and longer):

const char far * text1[]= "Text1";
const char far * text2[]= "Text2";

However, it appears that these constants are still in the CODE space. During linkage I get the following error:

*** ERROR L107: ADDRESS SPACE OVERFLOW
    SPACE:   CODE
    SEGMENT: ?CO?MAIN

How can I put the constants into the 'const far' memory type?

ANSWER

There are two solutions to this problem. The STRING compiler directive locates strings into various memory classes. At the beginning of your source file, specify:

#pragma STRING (far)   // locate string constants into 'far const' memory

You may define the explicit memory type of the constants by using another variable as shown below:

const char far       text1a[]= "Text1";
const char far       text2a[]= "Text2";
const char far * far text1[]= text1a;
const char far * far text2[]= text2a;

You may also look to the example ConstFar in the folder Keil\c51\Examples\FarMemory\1MB Constants on Classic 8051. This shows you some techniques that might be useful for you.

MORE INFORMATION

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

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.