www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: const?? When and why? This is ugly!

reply novice2 <sorry noem.ail> writes:
Denis Koroskin Wrote:

 // file 1
 char[] a = "hello";
 a[4] = '!';
 
 // file 2
 writefln("hello"); // prints 'hell!'

bad example :) why so behaviour? imho, it may be occur bacause of bad compiler design only. like C compiler for space optimization collect all mentioning of similar strings and allocate only one for all of occurence. and even in this case it must allocate it in non-writable memory section.
Mar 03 2009
parent "Denis Koroskin" <2korden gmail.com> writes:
On Wed, 04 Mar 2009 08:55:18 +0300, novice2 <sorry noem.ail> wrote:

 Denis Koroskin Wrote:

 // file 1
 char[] a = "hello";
 a[4] = '!';

 // file 2
 writefln("hello"); // prints 'hell!'

bad example :) why so behaviour? imho, it may be occur bacause of bad compiler design only. like C compiler for space optimization collect all mentioning of similar strings and allocate only one for all of occurence. and even in this case it must allocate it in non-writable memory section.

Yeah, that's why it is forbidden. It won't compile in D2.
Mar 03 2009