Wchar_t not signed or signed

In this link unsigned wchar_t there is typedefed like WCHAR. But I can not find this typedef type in my SDK winnt.hor mingw winnt.h.

wchar_t signed or unsigned?

I am using WINAPI in C.

+6
source share
3 answers

Signature wchar_tnot specified. The standard only says (3.9.1 / 5):

A type wchar_tmust have the same size, signature, and alignment requirements (3.11) as one of the other integral types, called its base type.

(On the contrary, the types char16_tand are char32_tclearly unknown.)

+11
source

Remember that the type will vary depending on the length of the platform.

Windows UTF-16, wchar_t - 2 . Linux 4 wchar_t.

+1

, .

1) MinGW (32-bit) + gcc 3.4.4:
---- snip ----
#include<stdio.h>
#include<wchar.h>
const wchar_t BOM = 0xFEFF;
int main(void)
{
    int c = BOM;
    printf("0x%08X\n", c+0x1000);
    return 0;
}
---- snip ----

0x00010EFF. wchar_t . movzwl _BOM, %eax. movSwl, movZwl.

2) FreeBSD 11.2 (64-bit) + clang 6.0.0:
---- snip ----
#include<stdio.h>
#include<wchar.h>
const wchar_t INVERTED_BOM = 0xFFFE0000;
int main(void)
{
     long long c = INVERTED_BOM;
     printf("0x%016llX\n", c+0x10000000LL);
     return 0;
}
---- snip ----

0x000000000EFF0000. wchar_t . , movq $-131072, -16(%rbp). 32- 0xFFFE0000 64- -131072.

3) , 2), RedHat ( ) + gcc 4.4.7: 0x000000000EFF0000. wchar_t .

printf WinAPI WCHAR, wchar_t ( ) C-to-ASM.

Note that the compilers in 1) and 3) are provided by the same provider, namely the GNU project. The answer is definitely platform dependent. (Will anyone test Visual C ++?)

0
source

All Articles