argument type const char* can pass string, buf why const wchar* can not pass wstring

riki via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Dec 26 21:29:44 PST 2015


On Sunday, 27 December 2015 at 04:54:07 UTC, Basile B. wrote:
> On Sunday, 27 December 2015 at 03:34:18 UTC, riki wrote:
>> void ccf(const char* str){}
>> void cwf(const wchar* str){}
>>
>> void main()
>> {
>>     ccf("aaa");    //ok
>>     cwf("xxx"w); // error and why ?
>> }
>
> IDK but usually the const storage class is used for narrow 
> strings because it allows to pass either `char[]` or `string[]`:
>
> ```
> void ccf(const char[] str){}
> void cwf(const wchar[] str){}
>
> void main()
> {
>     ccf("aaa");
>     cwf("xxx"w);
>     ccf("aaa".dup);
>     cwf("xxx"w.dup);
> }
> ```
>
> I'm actually surprised that one works, maybe both should fail.

windows api is use const(wchar)*, not const wchar[]


More information about the Digitalmars-d-learn mailing list