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

Janice Caron caron800 at googlemail.com
Mon Apr 28 00:17:00 PDT 2008


2008/4/28 Simen Kjaeraas <simen.kjaras at gmail.com>:
>  int main(string[] args)
>  {
>   char[] a = cast(char[])args[0];
>   a[2..5] = "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?

Yes, it's extremely bad. Casting away invariant is UNDEFINED BEHAVIOR,
and should never be done.

You should never need an explicit cast just to handle text!



More information about the Digitalmars-d mailing list