[Issue 2418] Same-value string (char[]) literals get overwritten (unlike array literals)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Oct 15 03:13:05 PDT 2008


http://d.puremagic.com/issues/show_bug.cgi?id=2418





------- Comment #6 from business3 at twistedpairgaming.com  2008-10-15 05:13 -------
(In reply to comment #5)
> The D spec says "String literals are immutable (read only)." even in D1. So
> code like this
> 
> char[] a = "ABC";
> a[0] = '!';
> 
> is illegal (and will segfault on linux!).
> 
> Array literals are allocated on the heap (the D spec explicitly says so) and
> will thus behave fundamentally different from string literals. 
> 

Alright, I see now. It does seem odd though that array literals would carry a
type that lacks any sort of const/read-only/immutable/etc qualifier, but is
still immutable anyway. Just another of D2's improvements I guess.

Out of curiosity, any idea if the lack of a run-time error on windows is due to
windows itself or just something DMD/OPTLINK does differently between the
platforms?


-- 



More information about the Digitalmars-d-bugs mailing list