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
  • "Am I missing something ?"

    The compiler can perform compile-time expression evaluations. But only when all parts of the equation have known values at compile time.

    If c1 is in another module, then the expression c2 = c1 + 25 can not be computed while compiling file2.c. But if the assign to c2 can't be computed directly at compile time, but instead at run time, then c2 can't be stored in a read-only memory region.

Reply
  • "Am I missing something ?"

    The compiler can perform compile-time expression evaluations. But only when all parts of the equation have known values at compile time.

    If c1 is in another module, then the expression c2 = c1 + 25 can not be computed while compiling file2.c. But if the assign to c2 can't be computed directly at compile time, but instead at run time, then c2 can't be stored in a read-only memory region.

Children
More questions in this forum