D2.0: an example of use-case for casting invariant away
Daniel Keep
daniel.keep.lists at gmail.com
Mon Jun 18 07:57:32 PDT 2007
Sean Kelly wrote:
> Walter Bright wrote:
>> Brad Roberts wrote:
>>> If it's actually treating the string as read-only, then I'd be
>>> tempted to change the extern(c) declaration to pass the argument as
>>> const char * rather than casting away the invariantness.
>>
>> The need to be able to cast away const-ness is to interface to
>> libraries that you cannot go and change.
>>
>> Also, the type system is not meant to be a straitjacket. If you
>> absolutely must do something, and you know what you are doing, there
>> should be a way to do it.
>
> That's understandable, but isn't it contrary to your statement that
> const in C++ is useless because of const_cast? Or is it the presence of
> a cast specifically intended to cast away const that you take issue with?
>
>
> Sean
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.
-- Daniel
More information about the Digitalmars-d
mailing list