From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/2277 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: type of wchar_t Date: Thu, 15 Nov 2012 12:53:40 +0100 Message-ID: <20121115115340.GH12537@port70.net> References: <20121115130950.17ed134c@keeper.home.local> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1352980432 21688 80.91.229.3 (15 Nov 2012 11:53:52 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 15 Nov 2012 11:53:52 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-2278-gllmg-musl=m.gmane.org@lists.openwall.com Thu Nov 15 12:54:03 2012 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1TYy1C-0007NR-Ex for gllmg-musl@plane.gmane.org; Thu, 15 Nov 2012 12:54:02 +0100 Original-Received: (qmail 29835 invoked by uid 550); 15 Nov 2012 11:53:52 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 29827 invoked from network); 15 Nov 2012 11:53:52 -0000 Content-Disposition: inline In-Reply-To: <20121115130950.17ed134c@keeper.home.local> User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:2277 Archived-At: * Yuri Kozlov [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""[0] 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)