ARM Technical Support Knowledge Articles

LOCATING VARIABLES TO FAR CONST SPACE

Applies to: C51 C Compiler

Answer


Information in this article applies to:


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

SEE ALSO

Article last edited on: 2005-07-15 09:53:29

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