How does "immutable" work.
egslava
egslava at gmail.com
Thu Aug 9 10:25:47 PDT 2012
Hello! Sorry for my English.
I read manual about "immutable" and "const" keyword:
http://dlang.org/const3.html
And tried to build my program:
http://dpaste.dzfl.pl/f803ae94
If I will change "immutable" to "const" output will not changed.
But why? Why output is look like this?
I would understand the output like this:
10
10
7FFF7E68AEB0
7FFF7E68AEB0
In this case, I would think - we just ignoring all assign
operators.
I would understand the output like this:
10
20
7FFF7E68AEB0
FFFFFFFFFFFFF
In this case, I would think - we just one more time located
memory and copied value of variable.
But why the output does look like this? How does this
construction work? Why memory addresses are same, assign is
working, but value of immutable variable doesn't change?
I would even think, that in compile-time compiler changes
writeln(x) to writeln(10), but why we can dereference "x"?
More information about the Digitalmars-d-learn
mailing list