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";
s=L"Test";
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";
^
test.c:5:6: error: incompatible types when assigning to type ‘struct Test’ from type ‘long int *’
s=L"Test";
^
Apparently, instead of the expected array, wchar_tI get an array long int. What is wrong here?
source
share