Keil Logo

C51: CONST VARIABLE STORAGE LOCATION

Information in this article applies to:

  • C51 Version 5.50

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.

FORUM THREADS

The following Discussion Forum threads may provide information related to this topic.

Last Reviewed: Friday, May 26, 2000


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.