Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > wchar_t aliasing

Reply
Thread Tools

wchar_t aliasing

 
 
tni
Guest
Posts: n/a
 
      08-07-2009
What are the aliasing rules for wchar_t with regards to its underlying
int type? E.g., if wchar_t is 16-bits, is it safe to cast to uint16_t?
 
Reply With Quote
 
 
 
 
Robert Hairgrove
Guest
Posts: n/a
 
      08-08-2009
tni wrote:
> What are the aliasing rules for wchar_t with regards to its underlying
> int type? E.g., if wchar_t is 16-bits, is it safe to cast to uint16_t?


Section 3.9.1., paragraph 5 "Fundamental types" of the C++ standard
tells you what you need to know. Basically, it's size and signedness are
implementation and platform dependent.
 
Reply With Quote
 
 
 
 
James Kanze
Guest
Posts: n/a
 
      08-08-2009
On Aug 7, 11:12 am, tni <(E-Mail Removed)> wrote:
> What are the aliasing rules for wchar_t with regards to its
> underlying int type?


That the underlying type is an integer type, whose values can
represent distinct codes for all members of the largest extended
character set specified among the supported locales.

In practice, constraints of backwards compatibility mean that
some widespread implementations aren't strictly conformant in
regard to that last criteria---formally, it means that if any
supported locale supports modern versions of Unicode, wchar_t
must have at least 21 bits.

> E.g., if wchar_t is 16-bits, is it safe to cast to uint16_t?


The results of the cast will be well defined on all systems, but
there's no guarantee that information won't be lost. wchar_t is
often 32 bits (and would almost certainly be 32 bits almost
everywhere without considerations of backwards compatibility,
which constraint Windows and AIX to 16 bit values).

--
James Kanze (GABI Software) email:(E-Mail Removed)
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
converting from windows wchar_t to linux wchar_t yakir22@gmail.com C++ 3 08-15-2008 09:04 AM
wchar_t -> UTF-8? Jon Willeke C++ 2 02-09-2004 08:05 AM
std::wstring, TCHAR, wchar_t and LPTSTR sorty C++ 4 11-25-2003 11:05 AM
string class that can convert between wchar_t and char Bren C++ 4 10-07-2003 03:24 PM
wchar_t wstring char string transformations Adrian Cornish C++ 2 07-12-2003 08:05 PM



Advertisments