[Exceptional C++ Style] Exceptional C++ Style - Item 24:Constant Optimization

Paul Grenyer paul at paulgrenyer.co.uk
Mon Jan 24 08:22:01 EST 2005


Hi

> From: David Nash <David.Nash at WallStreetSystems.com>
> > The only way using "const" can help the compiler, is when defining
something
> > const.  Then it could potentially be put into read-only memory.
Personally
> > I'm dubious even about this - const_cast (or plain old "C"-style cast)
can
> > still be used in this case.
>
> Except that would invoke the dreaded Undefined Behaviour.
>
> See 7.1.5.1/4

For those that don't have a copy of the standard:

Except that any class member declared mutable (7.1.1) can be object during
its lifetime (3.8) results in undefined behavior.

Regards
Paul

Paul Grenyer
email: paul at paulgrenyer.co.uk
web: http://www.paulgrenyer.co.uk
articles: http://www.paulgrenyer.dyndns.org/articles/

"15 miles to the love shack...."




More information about the Effective-cpp mailing list