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

const integral values across modules and ROM placement

Hi,

I have the following code:

file1.h

extern const unsigned char c1;

file1.c

const unsigned char c1 = 25;

file2.c

const unsigned char c2 = c1 + 25;

According to the documentation www.keil.com/.../armccref_ciabaidh.htm both variables should be placed in ROM but this doesn't happen.

I found that the variable c2 is not put in ROM and RW-data increases by 4 bytes.

but when c1 is in the same module(same .c file) as c2, RW-data doesn't increase and RO-data increases instead.

Am I missing something ?

Thanks in advance :)

Parents
  • It isn't a limitation of the tools, but a too high expectation by you.

    As far as expectations are concerned, this code shouldn't even be expected to compile at all --- not even with both definitions in the same translation unit.

    The C language definition explicitly requires that initializers for static variables must be "constant expressions". While it may seem that values of other, const-qualified variables should be allowed in constant expressions, they're not. An implementation is allowed to accept other forms (and this one apparently does), but it is generally unwise to expect such things to just work, much less to behave exactly in any particular way.

Reply
  • It isn't a limitation of the tools, but a too high expectation by you.

    As far as expectations are concerned, this code shouldn't even be expected to compile at all --- not even with both definitions in the same translation unit.

    The C language definition explicitly requires that initializers for static variables must be "constant expressions". While it may seem that values of other, const-qualified variables should be allowed in constant expressions, they're not. An implementation is allowed to accept other forms (and this one apparently does), but it is generally unwise to expect such things to just work, much less to behave exactly in any particular way.

Children