On Wed, 26 Jan 2011 15:32:58 -0500, Robert <[email protected]> wrote:


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?


It shouldn't. I don't know where the bug is. Please file a bug with a complete program (with a main() function) here: http://d.puremagic.com/issues/enter_bug.cgi

BTW, this has a segfault in Linux, so it's definitely trying to overwrite immutable data.

-Steve

Reply via email to