string initialization question.

bearophile bearophileHUGS at lycos.com
Fri Jul 30 09:46:20 PDT 2010


Steven Schveighoffer:
> >     char[] divider = new char[5];
> >     divider[] = '-';
> 
> That assigns 0xff to all divider chars, and then assigns '-'.  I think  
> there's a way to do it without the initial assignment.

In past there was some way to do that:
typedef char mchar = '-';
mchar[] divider = new mchar[5];

Now you have to initialize the dynamic array two times (using a char struct with alias this is probably not a good idea).
I have shown this problem, but I think Walter was not interested. Maybe LDC will able to optimize away the first initialization, I have an enhancement request for LLVM.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list