immutable string literal?

Steven Schveighoffer schveiguy at yahoo.com
Mon Feb 22 06:40:00 PST 2010


On Mon, 22 Feb 2010 09:27:57 -0500, strtr <strtr at spam.com> wrote:
> Thanks, I understand.
> But, how about a runtime error?
> Isn't a literal placed in easy to identify should-only-read memory?

A segfault is a runtime error.  The problem with Windows is it doesn't  
throw an error on writes to its data segment (unlike Linux).  In reality,  
the result of your program is undefined, so don't expect any help from the  
compiler/runtime.  There's nothing D1 can do about that.  In order for D  
to intercept that, it would have to instrument every write to memory, and  
that would cause performance problems like you wouldn't believe.

The short answer: Just don't do that.

-Steve


More information about the Digitalmars-d-learn mailing list