Do we really need const?

Janice Caron caron800 at googlemail.com
Wed Sep 19 11:51:18 PDT 2007


On 9/19/07, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
> Something tells me that this friend of yours would have done the same thing
> in D.  Is there a warning if you cast away const?  If not, there should be.
>
> Otherwise, D wouldn't have helped you in this case either...

Difficult to say. Everyone hesitates before typing "const_cast"! Even
when it's legitimate, it feels a bit naughty.

Trouble is, the "const_cast" keyword is not compulsory. With C++ is
that it isn't immediately obvious that a cast like "(void *)p" is
casting away const, but that's what everyone types, because it's
quicker than than the safe alternative "static_cast<void *>(p)".
That's why I'm hoping Walter will arrange it so that D's "cast(T)"
will refuse to cast away constness without a special syntax.



More information about the Digitalmars-d mailing list