On Fri, Mar 20, 2009 at 2:18 PM, Steven Watanabe
AMDG
Ovanes Markarian wrote:
On Fri, Mar 20, 2009 at 5:00 PM, Steven Watanabe
wrote: If you have a reference to const, the compiler cannot make any assumptions about whether it is modified or not, because of const_cast. Objects declared const are another matter, because it is undefined behavior to modify them.
Ok, I don't want to stick on this. In my initial post, I wrote that const provides a compiler an additional information which !!!might!!! be used usefully for optimization (!!!big doubt!!!). Emil writes that this info for sure is neglected, but I still don't think so.
It is theoretically possible for the compiler to use the const to optimize, but to do so it would have to prove that the functions which are called a) do not use a non-const reference to the same object. b) do not cast away the const.
Since b) is a subset of a), only a) needs to be proven. But const *can not* possibly help prove a).
(a) is independent of the presence or absence of const. Determining (b) is not very different from determining from scratch whether a variable is modified.
Exactly. Therefore, const in references does *not* provide anything the compiler can use for optimization purposes. If we're talking about an actual object, not a reference, that's a different story altogether. Since we keep discussing this, I went ahead and explained it all here: http://www.revergestudios.com/reblog/index.php?n=ReCode.Const. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode