string literals
Robert Fraser
fraserofthenight at gmail.com
Fri Jan 25 17:23:45 PST 2008
Saaa wrote:
> Didn't they both have immutable strings?
> I'm more in search of a way to make char[] not immutable anymore, for most
> things I do its only a hassle.
On UNIX systems, string literals are stored in the code segment. Thus,
modifying them will cause a segfault. In D 1.0, the compiler will let
you modify it, but the OS won't. In D 2.0, this rule is enforced by the
compiler. Even on Windows, modifying string literals is probably a bad idea.
To allow a string literal to be modified, copy it onto the heap with a
.dup .
More information about the Digitalmars-d-learn
mailing list