How does "immutable" work.
David Nadlinger
see at klickverbot.at
Thu Aug 9 11:17:44 PDT 2012
On Thursday, 9 August 2012 at 17:25:48 UTC, egslava wrote:
> If I will change "immutable" to "const" output will not changed.
> But why? Why output is look like this?
Just to repeat the gist of it: immutable is a guarantee that the
value stored in the variable will never change, and the compiler
is free to assume that when optimizing code. By using a cast and
then writing to the location, you have subverted the type system,
so all bets are off – in fact, your program is experiencing
undefined behavior.
David
More information about the Digitalmars-d-learn
mailing list