immutable string literal?
Steven Schveighoffer
schveiguy at yahoo.com
Mon Feb 22 07:45:05 PST 2010
On Mon, 22 Feb 2010 10:19:52 -0500, grauzone <none at example.net> wrote:
> Steven Schveighoffer wrote:
>> 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.
>
> Windows can protect memory as read-only too. Why dmd doesn't do that is
> a mystery. Even if .exe doesn't support read-only data segments, the
> runtime could have done so in early start-up code.
I'm not super-familiar with windows capabilities, but I'd venture a guess
that doing so would make exe's not compatible with older versions of
Windows.
But still, what does it matter? Just don't use D1 if you want a compiler
error, or don't try and trick the system into modifying ROM! There are
plenty of projects using D1 that just don't do this, and they are fine.
Implementing features to help people determine they created undefined
behavior is simply a waste of time. If you feel you can fix it, by all
means submit a patch, and it might get in.
-Steve
More information about the Digitalmars-d-learn
mailing list