In my code I have many of constants have same value. I cannot use same name of constant due to logic.
On optimization will keil take different memory of each or same memory.
I am using three setting of optimization: 1. O0 2. Cross + microlib + O2 3. Cross + Time + O3
Just to be clear, are you saying constant folding can be applied to constant variables, in addition to constant literals?
For example:
void func(void) { int a = 5; int b = a * 3; //... }
I would expect the optimizer to do the math and assign b = 15;
Where as:
const int a = 5; void func(void) { int b = a * 3; //... }
I would expect the expression "a * 3" to be evaluated at runtime.
The wikipedia article doesn't mention the second example, with constant variables.
Just note that 'const' means different things in C or C++.
In C++, the language allows it to be used as size of arrays etc. So really full constant folding optimizations all out with better compilers.
View all questions in Keil forum