cast(!const) proposal
Janice Caron
caron800 at googlemail.com
Sun Sep 9 08:01:23 PDT 2007
When I mentioned this on another thread, I got misunderstood, so I'm
going to try again, only this time being very, very clear, so
hopefully it will all make sense this time.
I propose that it shall be a compile-time error to cast away constness
or invariance with the existing syntax.
For example
const int n = 42;
auto p = &n;
auto q = cast(int *)p; /* Currently compiles. I propose that it should
be a compile error */
Since D is a nuts-and-bolts language, and Walter doesn't actually want
to prevent you from doing stupid things, there must be a way of
getting round that restriction. The intent is not to /prevent/ you
from being stupid - I mean, doing low level nuts-and-bolts things -
it's to require you to use a different syntax, so that you damn well
can't do it by accident. The syntax that I suggest for this is:
auto q = cast(!const)p;
This would allow the existing cast syntax to be made const-safe, and
is also consistent with the exisiting cast(const) syntax.
More information about the Digitalmars-d
mailing list