Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Kaz Kylheku <kaz@kylheku.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: wchar_t is useless |
| Date | 2011-11-21 16:17 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <20111121072256.446@kylheku.com> (permalink) |
| References | <jadmcb$b90$1@oravannahka.helsinki.fi> |
On 2011-11-21, Lauri Alanko <la@iki.fi> wrote: > I have recently written a number of posts regarding C's wide character > support. It now turns out that my investigation has been in vain: > wchar_t is useless in portable C programming, although I'm not quite That is false; it is useful. > So I looked at wchar_t. If __STDC_ISO_10646__ is defined and wchar_t > represents a unicode code point, this would be just perfect. But that's > not the case on all platforms. But that's okay, I thought, as long as I > can (with some platform-dependent magic) convert between unicode code > points and wchar_t. wchar_t is an integral type which represents an integral value. It does not represent a code point any more than "char" represents an ASCII value. > On Windows, it turns out, wchar_t represents a UTF-16 code unit, so a > code point can require two wchar_t's. That's ugly (and makes <wctype.h> This is a limitation of Windows. The Windows API uses 16 bit wide characters, so you can't get away from this no matter what language you write in on Windows. Redmond has decided that characters outside of the Unicode BMP (basic multilingual plane) are unimportant for its user base. So, if your programs has customers who are Windows users, you can safely assume that they have already swallowed this pill. You get a lot of internationalization mileage out of the BMP. Actually all the mileage. Above U+FFFF there is only academic crap. Anyone who cares about those characters is likely also going to be some kind of "freetard" who won't pay a dime for software. > But then I found out about the killer: on FreeBSD (and Solaris?) the > encoding used by wchar_t is locale-dependent! I would expect this "locale dependent" to mean that if, say, Japanese user is working with Shift-JIS files, then he or she can set that up in the locale such that when these files are processed by your program, the characters being read and written map to sane values of wchar_t (where sane == based on Unicode!). wchar_t does not have an encoding; it's an integral type. The encoding of wchar_t is binary enumeration: 000...0101 encodes 5, etc. Do you have some quotes from FreeBSD or Solaris documentation on this matter that are giving you concern? Post them. > So screw it all, I'll just use UTF-32 like I should have from the > beginning. But that just means you have to write your own library instead of just using C95 functions like wscspn, wcscpy, etc. What if you want to do printf-like formatting to a wide string? Can't use swprintf. Here is a better idea: just use wchar_t, forget about U+1XXXX on Windows because Microsoft has decided that one for your users already, and if locale-dependent streams give you an allergic reaction, handle your own decoding/encoding for doing I/O.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
wchar_t is useless Lauri Alanko <la@iki.fi> - 2011-11-21 14:14 +0000
Re: wchar_t is useless Kaz Kylheku <kaz@kylheku.com> - 2011-11-21 16:17 +0000
Re: wchar_t is useless James Kuyper <jameskuyper@verizon.net> - 2011-11-21 12:27 -0500
Re: wchar_t is useless jgk@panix.com (Joe keane) - 2011-11-24 20:07 +0000
Re: wchar_t is useless Kaz Kylheku <kaz@kylheku.com> - 2011-11-24 21:16 +0000
Re: wchar_t is useless James Kuyper <jameskuyper@verizon.net> - 2011-11-24 17:15 -0500
Re: wchar_t is useless Keith Thompson <kst-u@mib.org> - 2011-11-24 13:49 -0800
Re: wchar_t is useless Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-11-27 10:33 +0000
Re: wchar_t is useless Rui Maciel <rui.maciel@gmail.com> - 2011-11-25 14:17 +0000
Re: wchar_t is useless Vincenzo Mercuri <vincenzo.mercuri@yahoo.it> - 2011-11-25 15:27 +0100
Re: wchar_t is useless Vincenzo Mercuri <vincenzo.mercuri@yahoo.it> - 2011-11-25 15:29 +0100
Re: wchar_t is useless Dann Corbit <dcorbit@connx.com> - 2011-11-22 09:50 -0800
Re: wchar_t is useless blp@cs.stanford.edu (Ben Pfaff) - 2011-11-21 10:42 -0800
Re: wchar_t is useless jmclnx@SPAMisBADgmail.com (Jack McCue) - 2011-11-21 19:18 +0000
Re: wchar_t is useless Kaz Kylheku <kaz@kylheku.com> - 2011-11-21 21:02 +0000
Re: wchar_t is useless Lauri Alanko <la@iki.fi> - 2011-11-21 22:07 +0000
Re: wchar_t is useless Kaz Kylheku <kaz@kylheku.com> - 2011-11-21 23:54 +0000
Re: wchar_t is useless Lauri Alanko <la@iki.fi> - 2011-11-22 01:15 +0000
Re: wchar_t is useless Kaz Kylheku <kaz@kylheku.com> - 2011-11-22 01:57 +0000
Re: wchar_t is useless Lauri Alanko <la@iki.fi> - 2011-11-22 09:28 +0000
Re: wchar_t is useless Acid Washed China Blue Jeans <chine.bleu@yahoo.com> - 2011-11-21 11:11 -0800
Re: wchar_t is useless "christian.bau" <christian.bau@cbau.wanadoo.co.uk> - 2011-11-24 08:43 -0800
Re: wchar_t is useless 88888 Dihedral <dihedral88888@googlemail.com> - 2011-11-24 16:42 -0800
csiph-web