------- Comment #3 from pluto at agmk dot net 2009-10-28 12:03 ------- (In reply to comment #2) > 4.3.x and newer gcc says: > > pr31043.c:3: warning: 'pi' initialized and declared 'extern'
so, lets get correct testcase: #ifndef pi_hpp #define pi_hpp extern double const pi; extern double foo(); #endif #include "pi.hpp" #include <cmath> double const pi = M_PI; double foo() { return pi; } now, it compiles cleanly with `g++ -Wall -Wextra -O2 -S pi.cpp` > So, if you don't want to be treated as a constant, write > > double pi = M_PI; > > and this will generate the code you are looking for: but in this testcase i don't want to drop const. > As far as double copy when "double const pi = M_PI;" is used, tree optimizers > already propagate constant to return, as evident from optimized dump: > > foo () > { > <bb 2>: > return 3.141592653589793115997963468544185161590576171875e+0; > > } > > And this constant is handled in different way than its shadow in the memory. could you explain why? they are identicial constants. -fmerge-constants should do something with this. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31043