Why D const is annoying
Jesse Phillips
jessekphillips+D at gmail.com
Mon Dec 12 16:58:10 PST 2011
On Sun, 11 Dec 2011 19:40:42 +0100
Mafi <mafi at example.org> wrote:
> void f(ref const(int)* a, const(int)* b) {a = b; }
> void main() {
> immutable(int)* a;
> auto b = (new int[](5)).ptr;
> f(a, b);
> //if this compiles I have just assigned a mutable pointer
> //to an immutable one
> }
>
> With the above definition using inout, such a call would be
> disallowed.
Just gave this code a try:
void f(ref const(int)* a, const(int)* b) {a = b; }
void main() {
const(int)* a;
immutable(int)* b;
auto c = (new int[](5)).ptr;
f(a, c);
f(b, c); //test.d(7): Error: cast(const(int)*)b is not an lvalue
}
More information about the Digitalmars-d
mailing list