string literals

Saaa empty at needmail.com
Fri Jan 25 17:47:36 PST 2008



> On UNIX systems, string literals are stored in the code segment.
If you load a file into a char[][], will the file be stored in the code 
segment?
Wouldn't you normally want to edit it after loading?

But shouldn't there be an way (per variable) to force the compiler to not 
store it like that?

> 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 .

I know this, although it just says it creates a dynamic array. How do you 
know that the .dup dynamic array is not read-only.




More information about the Digitalmars-d-learn mailing list