4

Say I have the following:

wchar_t *str = L"Hello World!";

Is L"Hello World!" encoded in UTF-16LE or UTF-16BE?

Note: I am using Visual C++ 2010.

user4582812
  • 591
  • 1
  • 4
  • 16

2 Answers2

4

You can safely assume that any wide character string on Windows uses little endian UTF-16 - see this answer for a more elaborate dive: Can I safely assume that Windows installations will always be little-endian?

Community
  • 1
  • 1
Johann Gerell
  • 24,991
  • 10
  • 72
  • 122
3

Depends on your editor, VS2010 uses UTF-8 by default :) With a BOM so the compiler can tell. It can be changed, click the arrow on the Save button.

The compiler will turn it into UTF-16LE in the object file, there are no remaining big-endian machines supported by msvc++ that I know of, ARM cores all run little-endian these days.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536