Casting away const and invariant
James Dennett
jdennett at acm.org
Sun Sep 9 13:46:01 PDT 2007
Janice Caron wrote:
>> If casting away const in D always involves undefined behavior
>> (and not only when the resulting object is modified) then it
>> should certainly be detected and disallowed at compile time.
>
> Of course.
>
> However, according to Walter, I quote: "Because a static type system
> can be a straitjacket, there needs to be a way to circumvent it for
> special cases."
>
> and... "The ability to cast away invariant-correctness is necessary in
> some cases where the static typing is incorrect and not fixable, such
> as when referencing code in a library one cannot change. Casting is,
> as always, a blunt and effective instrument, and when using it to cast
> away invariant-correctness, one must assume the responsibility to
> ensure the invariantness of the data, as the compiler will no longer
> be able to statically do so."
>
> Both of those quotes indicate that D requires a way to do the
> unthinkable. Therefore, as stated above, and (somewhat better) on
> another thread, I argue that the solution is to disallow it - except
> with some special, unambiguous syntax, which makes plain you are
> deliberately breaking the rules. Preferably something greppable. See
> other thread.
It may well be necessary; if it is, the behaviour must be defined
so that it _works_.
-- James
More information about the Digitalmars-d
mailing list