immutable

Robert robert.welin at hotmail.com
Wed Jan 26 12:32:58 PST 2011


Hello,
I have just recently started programming in D (a very pleasant experience so
far I must say), but when experimenting with the the immutable attribute I
discovered that the following code does not generate a compile time nor a
runtime error:

//Decalare immutable string
immutable char[] buf = "hello";

//Print the value of buf
writefln("buf = %s",buf);

//Change buf by using standard input
stdin.readln(buf);

//Print buf again
writefln("buf = %s",buf);


This is a bit confusing to be because I had assumed that immutable data really
would be immutable (without casting). Why does the code above work?

Cheers
Nilew


More information about the Digitalmars-d mailing list