![]() ![]() The %s and %hs format specifiers represent an narrow string.When Unicode support formally arrived in C99, the C standard committee chose a different model for printf format strings. It also makes converting existing ANSI code to Unicode much simpler, since you can keep using %s, and it will morph to do what you need. If the code is compiled as ANSI, the result is char buffer Īnd if the code is compiled as Unicode, the result is⁴ wchar_t buffer īy following the convention that %s takes a string in the same width as the format string itself, this code runs properly when compiled either as ANSI or as Unicode. _tprintf(TEXT("The string is %s.\n"), buffer) The idea behind this pattern was so that you could write code like this: TCHAR buffer The %ws and %ls format specifiers represent a wide string regardless of the width of the format string.The %hs format specifier represents a narrow string regardless of the width of the format string.The %S format specifier represents a string in the opposite width as the format string.The %s format specifier represents a string in the same width as the format string.As for printf-style format strings, here’s what we ended up with: The result was functions like wcscmp, wcschr, and wprintf. This meant that Windows had to invent Unicode support in the C runtime. Windows adopted Unicode before the C language did. ![]() This was the encoding recommended by the Unicode Consortium because Unicode 1.0 supported only 65536 characters.² The Unicode Consortium changed their minds five years later, but by then it was far too late for Windows, which had already shipped Win32s, Windows NT 3.1, Windows NT 3.5, Windows NT 3.51, and Windows 95, all of which used UCS-2.³īut today we’re going to talk about printf-style format strings. As a result, Windows’s solutions to many problems differ from solutions adopted by those who waited for the dust to settle.¹ The most notable example of this is that Windows used UCS-2 as the Unicode encoding. Windows adopted Unicode before most other operating systems. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |