const issues and more!

Saaa empty at needmail.com
Mon Jan 14 14:48:22 PST 2008


My intuition tells me that a char[] is an array of chars, just like int[] is 
an array of ints.
If you want something special like a string literal you can use string or 
stringl or something alike.


void function(in out int i){}

> :)> Will this work as well?
> int[] def = [ 1, 2, 3 ];
> def[0]=0;
> int[] def2 = [ 1, 2, 3 ];
> assert(def2[0..2] == [ 0, 2, 3 ]);
>
>>> to compile, then you are free to modify the constant "text"!  For 
>>> example, in D 1.0 this works:
>>>
>>> char[] text = "text";
>>> text[0] = 'n';
>>> char[] text2 = "text";
>>> assert(text2 == "next");
>>>
>>> These kinds of errors are subtle and hard to find.  This is why you are 
>>> not allowed to have a non-const or invariant pointer to invariant data 
>>> such as string literals.
>>>
>>> -Steve
>>>
>>
>>
>
> 





More information about the Digitalmars-d mailing list