Is a long string literal of type long int *?

According to the answers in this question, the literal seems to L"test"have a type wchar_t[5]. But the following code with GCC seems to say something different:

int main()
{
    struct Test{char x;} s;
    s="Test"; // ok, char* as expected
    s=L"Test"; // ??? I'd expect wchar_t*
    return 0;
}

This is how I compile it (gcc 5.2, but the same results with 4.5 and 4.8):

$ gcc test.c -o test -std=c99
test.c: In function ‘main’:
test.c:4:6: error: incompatible types when assigning to type ‘struct Test’ from type ‘char *’
     s="Test"; // ok, char* as expected
      ^
test.c:5:6: error: incompatible types when assigning to type ‘struct Test’ from type ‘long int *’
     s=L"Test"; // ??? I'd expect wchar_t*
      ^

Apparently, instead of the expected array, wchar_tI get an array long int. What is wrong here?

+4
source share
1 answer

The type wchar_t is not a fundamental type, for example char. This is a synonym defined by the implementation of integer type 1 .


1 ( : ISO/IEC 9899: 201x 7.19 2.)
wchar_t, , , ;

+2

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


All Articles