ARM Technical Support Knowledge Articles

CONST VARIABLE STORAGE LOCATION

Applies to: C51 C Compiler

Answer

Information in this article applies to:


QUESTION

When I declare a constant like this:

const char c = 42;

Most compilers would place the resultant byte in the code segment. C51 seems to place it in the data segment. I realize I could simply write:

const char code c = 42;

But I'm curious as to why the const qualifier isn't enough on its own.

ANSWER

The const qualifier tells the compiler that the variable cannot be written (is constant). This has no influence on the memory space where the variable is located. You can define a constant variable in every memory space (data, idata, xdata ...). If you omit the memory space then the default memory space is used, which depends on the memory model chosen.

Article last edited on: 2000-05-26 00:00:00

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