I can't understand how cast coexist with immutability. Consider the code:
        immutable immutable(int)[4] buf;
        auto x=buf[0];
        auto p=buf.ptr;
        
        auto i=cast(int[]) buf;
        i[]=1;
        
        assert(buf.ptr == p);
        assert(buf[0] != x);

I've just modified immutable data, is it normal?
Another, ever simpler, code:
        immutable a=0;
        auto b=cast(int*) &a;
        *b=1;
        assert(&a == b);
        assert(a != *b);
Last two assertions both succeed and really puzzle me. What is pointer in D at all?

Reply via email to