expected array behaviour

John Reimer terminal.node at gmail.com
Thu Jan 1 16:43:30 PST 2009


Hello Jarrett,

> On Thu, Jan 1, 2009 at 5:55 PM, Mike James <foo at bar.com> wrote:
> 
>> I have a function that uses 2 array strings defined similar to
>> this...
>> 
>> const char[] array1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char[]  array2 =
>> "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
>> 
>> If I make a change to a char in array1 it also changes the same in
>> array2. But if I define the arrays as follows...
>> 
> You'd get a runtime error if you were using Linux.  For some reason
> string literals are not read-only, or Windows doesn't respect it, or
> something like that.  Modifying either array1 or array2 is technically
> illegal.  So, uh, don't do it.
> 


Yes, that's one advantage to Linux.  String literals aren't read-only on 
Win32.  This is unfortunate because it means that these sort of bugs are 
significantly harder to diagnose on Windows than on Linux.  I remember that 
this was a bug in a early DUI version (now GtkD).  It's was pretty easy to 
spot on Linux because of the runtime error.

-JJR




More information about the Digitalmars-d-learn mailing list