D2.0: an example of use-case for casting invariant away
Walter Bright
newshound1 at digitalmars.com
Mon Jun 18 11:23:55 PDT 2007
Daniel Keep wrote:
> Walter's said on a few occasions that the problem with C++'s const is
> that casting away const is a *well-defined* operation. That means that
> const cannot be used to do any kind of optimisation, since it doesn't
> really mean anything.
>
> The new page on const specifically states that casting away const or
> invariance is *not* a well-defined operation, and you'd better know what
> you're doing when you do it.
More specifically, in C++, you can cast away const-ness and then modify
the underlying data, and this is defined to be legal, defined behavior.
With D, you can cast away const-ness, that is legal. But if you
subsequently modify the underlying data, that is undefined behavior.
More information about the Digitalmars-d
mailing list