Workarounds for Lack of Mutable Keyword

Janice Caron caron800 at googlemail.com
Thu Apr 3 00:08:17 PDT 2008


On 03/04/2008, Janice Caron <caron800 at googlemail.com> wrote:
> One problem with this function is demonstrated by
>
>     string s = "hello world";
>
>     ConstAssign(h[0],'j');

Yikes! I think I must be going mad. That's too many typos for one day!
Need more coffee. The h should have been an s.

     string s = "hello world";

     ConstAssign(s[0],'j');

>  Oops - it assigns invariants too! Even if you can be sure there are no
>  other threads vying for access to s, still, those chars might be in a
>  hardware-locked ROM segment.
>
>  There's a reason why casting away const is not defined.



More information about the Digitalmars-d mailing list