This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

put const variables into code-segment

Hi.

I want to put a (large) table of constant values into the code-segment, because I'm very low on RAM but have plenty of program-ROM.

The C51-manual on page 88 says "Constant variables may also be stored in program memory".

How is this possible?

Thanks, Patrick

Parents
  • "I realize that calling something by the oxymoron 'constant variable' may have snuck into C litterature but it it still impossible to be 'a constant AND a variable'."

    Probably the real error here is the use of the term "variable" - "identifier" would probably be better.

    Actually, to a 'C' compiler, const just means "non-writable."

    So, if you had a memory-mapped read-only port, you could mark it as const to make sure that any attempt to write it would be flagged as an error - although it could be anything but "constant" in the true English sense of the word!

    See also the use of const with the input parameters to functions; eg,
    http://www.keil.com/support/man/docs/c51/c51_strchr.htm

Reply
  • "I realize that calling something by the oxymoron 'constant variable' may have snuck into C litterature but it it still impossible to be 'a constant AND a variable'."

    Probably the real error here is the use of the term "variable" - "identifier" would probably be better.

    Actually, to a 'C' compiler, const just means "non-writable."

    So, if you had a memory-mapped read-only port, you could mark it as const to make sure that any attempt to write it would be flagged as an error - although it could be anything but "constant" in the true English sense of the word!

    See also the use of const with the input parameters to functions; eg,
    http://www.keil.com/support/man/docs/c51/c51_strchr.htm

Children
No data