As an integral expression of constants, the compiler has every right to use permanent folding to remove it from the program. This is not the case if you accept his address. In addition, the modern optimizing compiler can use LTO, inlining, and persistent folding to do the same with c3 and c4, if possible.
If you do not take the address of a variable, the compiler is not required to allocate it if it can generate code with equivalent results in accordance with the as-if rule.
Edit: persistent folding is where the compiler evaluates expressions at compile time rather than at run time. For example, you can legally execute int x[3 + 4]; where 3 + 4 is evaluated at compile time. Some examples, especially those related to MCOs, are standardized, but implementation can do more if possible. LTO is the optimization of communication time when the compiler performs optimization between translation units when they are connected to each other.
This means that the compiler can embed the body my_f , and then (depending on the body) the constant collapse it to make c3 constant expression, and then constantly dump it to where it was used, rather than highlighting It. For c4 the LTO can provide value c4 as a constant expression, and in this case it can also be folded and removed.
C ++ 11 has constexpr functions that allow you to do much more in this area.
Puppy source share