Date: Thu, 15 Nov 2012 12:53:40 +0100 From: Szabolcs Nagy <nsz@...t70.net> To: musl@...ts.openwall.com Subject: Re: type of wchar_t * Yuri Kozlov <yuray@...yakino.ru> [2012-11-15 13:09:50 +0400]: > > arch/x86_64/bits/alltypes.h.sh > #ifndef __cplusplus > TYPEDEF int wchar_t; > #endif > > > arch/i386/bits/alltypes.h.sh > #ifndef __cplusplus > #ifdef __WCHAR_TYPE__ > TYPEDEF __WCHAR_TYPE__ wchar_t; > #else > TYPEDEF long wchar_t; > #endif > #endif > > (__WCHAR_TYPE__ is not defined everyware, so TYPEDEF long wchar_t;) > > arch/arm/bits/alltypes.h.sh > #ifndef __cplusplus > TYPEDEF unsigned wchar_t; > #endif > > > Why type of wchar_t is so differs? > because wchar_t is a broken concept and platform abis and compilers have gratitous incompatibilities you cannot have arbitrary definition because the L'x' character constant and L"" string literal has a given type in the compiler and you should use the same in the wchar_t typedef (different int types are not compatible, they can be converted if the range is ok, but eg. calling function through incompatible function pointer type is undeinfed behaviour) in c++ wchar_t is a keyword because otherwise polimorphism and strict type checking of int vs wchar_t would not work (wchar_t must be distinct from any other int type) in c99 the compiler could be loose and allow pointer to any sufficiently aligned+sized+signed integer type to work with L"", so eg. wchar_t could be long or int as well on a 32bit platform c11 has generics (implemented in the compiler) so the compiler must have a type internally for L'' or L"" and wchar_t must be defined as that type so we either use the __WCHAR_TYPE__ defined by the compiler (when it's defined), or use the abi specs (which gives the align+size+sign information and hopefully compilers agree on a single int type when there are multiple choices)
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.