Representation of wchar_t and char in WinDbg

Note:

/*
* Trivial code
*/
wchar_t *greeting = L"Hello World!";
char *greeting_ = "Hello World!";

Windbg:

0:000> ?? greeting
wchar_t * 0x00415810
"Hello World!"
0:000> ?? greeting_
char * 0x00415800
"Hello World!"

0:000> db 0x00415800
00415800  48 65 6c 6c 6f 20 57 6f-72 6c 64 21 00 00 00 00  Hello World!....
00415810  48 00 65 00 6c 00 6c 00-6f 00 20 00 57 00 6f 00  H.e.l.l.o. .W.o.
00415820  72 00 6c 00 64 00 21 00-00 00 00 00 00 00 00 00  r.l.d.!.........

Question:

  • What is the purpose of the NULL character : 00between ASCII characters in wchar_t- Win32 ?
+3
source share
3 answers

wchar_tis a wide character string, so each character takes up 2 bytes of memory. "H" is a wchar_tequal to 0x0048. Since x86 is unimportant, you see bytes in memory in the order 48 00.

db in windbg resets bytes and shows how it is treated as an ASCII string, therefore, HEL ... the output you see. You can use 'du' to unload memory as a string in Unicode.

+9
source

, wchar_t 16- , . UTF-16. , , ASCII, < 256, .

+2

wchar_t for unicode , and char for standard 8-bit ascii

in wchar_t, each character is represented by 16 bits, but the "standard" characters sit in the lower half of the graph. Traditional Chinese , for example, would have other values ​​than 00 for these bytes.

+1
source

Source: https://habr.com/ru/post/1706686/


All Articles