Wide characters support in D

torhu no at spam.invalid
Mon Jun 7 18:29:58 PDT 2010


On 08.06.2010 01:16, Ruslan Nikolaev wrote:
> Ok, ok... that was just a suggestion... Thanks, for reply about "Hello world" representation. Was postfix "w" and "d" added initially or just recently? I did not know about it. I thought D does automatic conversion for string literals.
>

There is automatic conversion, try this example:

---
//void f(char[] s) { writefln("char"); }
void f(wchar[] s) { writefln("wchar"); }


void main()
{
   f("hello");
}
---

As long as there's just one possible match, a string literal with no 
postfix will be interpreted as char[], wchar[], or dchar[] depending on 
context.  But if you uncomment the first f(), the compiler will complain 
about there being two matching overloads.  Then you'll have to add the 
'c' or 'w' postfixes to the string literal to disambiguate.

For templates and type inference, string literals default to char[].

This example prints 'char':
---
void f(T)(T[] s) { writefln(T.stringof); }

void main()
{
   f("hello");
}
---


More information about the Digitalmars-d mailing list