Reputation: 1491
I use Ubuntu 18.04 and gcc 7.5.0. I have a library which is compiled with -fshort-wchar. I have noticed that using std::wstring
in the library may leads to the segmentation fault. I have found a similar topic. There is an explanation:
-fshort-wchar is not usable if you want to interact with any part of the standard library or third-party library code using the correct (32-bit) definition of wchar_t.
I understand that I can't use std::wstring
when a library is compiled with -fshort-wchar
but what with the other standard library content ? Why I can't interact with any part of the standard library, for example std::vector ?
Upvotes: 1
Views: 226
Reputation: 117298
-fshort-wchar sets the size of wchar_t to 2 bytes
Now think about what will happen if you use a part of the standard library that is not header only. A big part of the standard library is compiled into a library that you link with (libstdc++
/ libc++
). When that was compiled -fshort-wchar
was not used and the size of the wchar_t
is therefore 4 bytes in the library.
Upvotes: 3