Is all this Invarient **** er... stuff, premature optimisation?

Simen Kjaeraas simen.kjaras at gmail.com
Sun Apr 27 17:50:12 PDT 2008


On Mon, 28 Apr 2008 02:44:14 +0200, <p9e883002 at sneakemail.com> wrote:

> On Mon, 28 Apr 2008 02:14:19 +0200, "Simen Kjaeraas"
> <simen.kjaras at gmail.com> wrote:
>> <p9e883002 at sneakemail.com> wrote:
>>
>> Is this what you wanted to write?
>>
>> int main(string[] args)
>> {
>>    char[] a =3D cast(char[])args[0];
>>    a[2..5] =3D "XXX";
>>    writefln(a);
>>    return 0;
>> }
>> This compiles and runs, and seems to do what you describe. Sure,  
>> there's=
>>  a
>> cast there, but it's not all that bad, is it?
>
> No. You missed out uppercasing the string before replacing the slice.


That's why I replied to my own post stating just that.
Anyways, Gide got it right. A .dup is the correct way, a cast is wrong.

-- Simen



More information about the Digitalmars-d mailing list