mutable constant?

anonymous anonymous at example.com
Wed Jun 26 16:45:22 PDT 2013


On Wednesday, 26 June 2013 at 15:48:42 UTC, Jonathan M Davis 
wrote:
> It doesn't break anything. It just shows the need for pure.

Really? In the following simplified code I see mutation of an 
immutable variable, which should not be possible, of course. That 
is breaking the type system, no? What am I missing?

import std.stdio;
int* point;
struct TplPoint {
     int _point;
     this(int x) {
         _point = x;
         point = &_point;
     }
}
void main() {
     immutable TplPoint my = TplPoint(42);
     writeln(my._point); // 42
     *point = 13; // uh-oh
     writeln(my._point); // 13 !!!
}


More information about the Digitalmars-d-learn mailing list