Keil Logo

C51: Memory Classes for Strings and String Pointers


Information in this article applies to:

  • C51 Version 7 and later

QUESTION

I am using the Cx51 Compiler with code banking and variable banking and am having a problem with string allocation. When I declare a constant char string:

const char * far myStr = "Hello";

the compiler locates the pointer in HDATA memory. However, I want all my constants to be located in HCONST.

How can I solve this problem?

ANSWER

Your example defines a pointer in far that points to const char that may be located in any memory space. This is probably not what you want.

The following code example does what you describe:

#pragma STRING (FAR)  // locate strings in far const space

const char * const far myStr = "Hello";

The STRING directive specifies that the const far memory space is the default location for implicit text strings. And,

const char * const far myStr = "Hello";

defines a pointer in const far that points to const char. Now, all your variables will be located in the HCONST memory class.

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.