String implicit casts
Derek Parnell
derek at psych.ward
Thu Mar 9 15:18:51 PST 2006
On Thu, 9 Mar 2006 22:56:04 +0000 (UTC), lightoze wrote:
> I use this two functions:
>
> void x(char[] x) {}
> void x(wchar[] x) {}
>
> This works:
>
> x(cast(char[])"x");
> x(cast(wchar[])"x");
>
> This do not:
>
> x("x");
>
> I have found nothing about it in manual, can anyone tell me if it is normal or
> not?
It is 'normal' but not expected. Most people assume that an unadorned
string literal is a char[] but it turns out that the compiler is a little
more discerning. But in general, if the compiler cannot decide which utf
character type to encode the literal with, it complains and you have to
tell it what to do. Fortunately, we can add a suffix to the literal to tell
the compiler what we want instead of the chunky cast syntax. In your case
...
x( "x"c );
x( "x"w );
--
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocracy!"
10/03/2006 10:15:09 AM
More information about the Digitalmars-d
mailing list