February 22, 2010Re: immutable string literal?
Posted in reply to strtr
On Mon, 22 Feb 2010 11:24:36 -0500, strtr <firstname.lastname@example.org> wrote: > Steven Schveighoffer Wrote: > >> >> 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 > > The point is that I didn't know the char array literal to be immutable. > I thought it would be like any other array literal. Now I get to recheck > my whole project to see whether I ever change an immutable array. "Use > D2" is not really an argument in this case as I didn't even know I was > using a "trick". For me it would have been great if the compiler would > have segfaulted on this undefined behaviour. As I said before, it's not possible for the compiler to check this. It's unfortunate that array literals are treated differently than strings, and perhaps more unfortunate that Windows doesn't throw a loud error when this occurs. I don't see any way to "fix" that, because D1's spec is frozen. The crappy answer is, you'll just have to live with it. On the bright side, after frustratingly having to examine your code again for this problem, you are less likely to make this mistake in the future :) -Steve