if WCHAR_TYPE is "short int" (cygwin) the following program produce always short wchar. Please treat this option like -fno-short-enum #include <wchar.h> int x = sizeof (wchar_t); $ gcc -S -o - foo.c $ gcc -fshort-wchar -S -o - foo.c $ gcc -fno-short-wchar -S -o - foo.c
This is a header issue which means it is not a GCC bug.
I disagree wchar_t is a building type. Indeed L"aa" should expand to 16 bits packed char with short wchar and 32 bits with no-short-wchar. Due to the LNaaN constant specification wchar_t is more than a typedef stuff. Bastien
BTW i have checked the source code, and if my memory is correct wchar_t is defined as MODIFIED_WCHAR_T = fshortwchar ? "Short int" : WCHAR_T Where wchar_t is defined by the architecture config. The problem is under arch where WCHAR_T is "short int" this flag have no effect. This flag should behave as short-enum where arch specify a default that could be overwritten Bastien
It is a builtin type (for C++ it is exposed as the keyword, wchar_t). For C, the headers define the type, see the preprocessed source to show that is the case.
ok thanks it is defined in the header and in this case they are two bugs. Try the following program #include <stdio.h> typedef __WCHAR_TYPE__ wchar_t; wchar_t a[] = L"aa"; int s = sizeof(wchar_t); void main() { printf("%i\n",s); } under linux it output 4 under linux with -fno-short-char it output 4 under linux with -fshort-char it output 2 under cygwin it output 2 nder linux with -fno-short-char it output 2 (BUG here) under linux with -fshort-char it output 2
I have checked with gcc -E the following program: typedef __WCHAR_TYPE__ wchar_t; under linux it output typedef int wchar_t under linux with -fno-short-char it output typedef int wchar_t under linux with -fshort-char it output typedef short unsigned int wchar_t under cygwin it output typedef short unsigned int wchar_t nder linux with -fno-short-char it output typedef short unsigned int wchar_t (BUG) under linux with -fshort-char it output typedef short unsigned int wchar_t Bastien
Sorry replace the last linux by cygwin
Any news of this bug ?
Looking at http://msdn.microsoft.com/en-us/library/dh8che7s(v=vs.71).aspx I see that wchar_t is "typically" defined as "unsigned short". MSVC provides a /Zc:wchar_t that causes wchar_t to become "a native type" that maps to _wchar_t. Currently the mingw.org wchar.h file includes the stddef.h file after defining __need_wchar_t. I need to walk through stddef.h to determine if we (mingw.org) needs to define some other macro based on the provided options. However, I'm feeling like this will be a coordinated effort between both parties. I don't know about Cygwin's versions of the headers, they should match more to what Linux defines.