Flitzpiepe Flitzpiepe - 2 months ago 13
C Question

UEFI programming: how to initialize a CHAR16 unicode string?

i have to use some char16-wide strings for uefi programming. How can i initialize them easily?
CHAR8 is easy:

CHAR8 *Str = "yehaw\0";


CHAR16 meanwhile is hard working that way, therefor i chose this initialization:

CHAR16 *Str;
Str = AllocatePool(6*2); //AllocatePool allocates bytewise
Str = ('y','e','h','a','w','\o');


So question is: What whould be the right and what the easy way to initialize CHAR16 strings?

Answer

If you have the c standard library and are using a conformant C/C++ compiler, typically prefixing a string with L works for declared strings.As in :

 CHAR16 *Str =  L"yehaw";

works. However, why not use the ubiquitously accepted type of

 wchar_t

?