ARM Technical Support Knowledge Articles

MEMORY CLASSES FOR STRINGS AND STRING POINTERS

Applies to: C51 C Compiler

Answer


Information in this article applies to:


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

SEE ALSO

Article last edited on: 2007-07-06 01:31:03

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential