I am tempted to say that what you want does not make sense. A constant is something that does not change its value, and not something that can change its value once or twice. If you want a global variable, just make it volatile.
On the other hand, if you have values ββwith a constant constant, you simply declare and initialize them at the same time, following the general C ++ directive to declare as close as possible to the site of use. For example, note the use of constants in the following local area:
for (auto it = v.begin(), end = v.end(); it != end; ++it) { const Foo & x = *it; const std::size_t n = x.get_number_of_bars(); // use x and n ... const bool res = gobble(x, zip(n)); if (res && shmargle(x)) { return 8; } }
Here, the compiler may not even generate any special code for variables at all, if their value is already known by other means.
Kerrek SB
source share