Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #43271

Re: wchar_t: signed or unsigned?

Newsgroups comp.lang.c
Date 2014-04-22 03:21 -0700
References <4cial9tecgiks7ov2q3c1oo53492kvf3ti@4ax.com>
Message-ID <978c9431-6725-4fd0-83ca-8f426b94de8d@googlegroups.com> (permalink)
Subject Re: wchar_t: signed or unsigned?
From Malcolm McLean <malcolm.mclean5@btinternet.com>

Show all headers | View raw


On Monday, April 21, 2014 5:55:52 PM UTC+1, DSF wrote:
> Hello, group!
> 
>   Is wchar_t signed or unsigned?  Is it different in C++ than in C? Or
> is it one of those things left up to the compiler writer?
> 
>   I need to know because I'm dealing with an array of chars, but they
> are treated by the outside world as ints.  EOFs and error codes are
> expressed in negative values.  So I am using unsigned chars for the
> array to avoid the possibility of one of the array members being > 127
> and being sign extended to a negative int.
> 
>   I also have an array of wchar_t for dealing with Windows 16-bit
> Unicode.  I don't know if Unicode utilizes the fifteenth bit, but I
> don't want to take any chances.  In my compiler, wchar_t is defined as
> "unsigned short" so I don't expect any problems.  But I'd like to know
> the official word on it.  I did Google the question, but found page
> after page espousing which form of Unicode is best.  Interesting
> reading, but not an answer.
> 
It depends how portable you need to be.
16 bits aren't enough to encode all the glyphs in every language in the world, so if you must support
all of Unicode, you can't use Windows wchar_t at all. However the higher Unicode numbers are used
for pretty marginal alphabets, 15 bits is enough for most purposes. Unicode defines a series of so-
called "non-character code points" of which 0xFFFF is one, You can use these internally, but you can't
export unicode sequences containing these reserved code points.
I don't know if any Windows fonts actually use Unicode characters 0x7FFFF to 0xFFFFF. Obviously you
won't be able to support them if you use bit 15 as an internal flag.  

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

wchar_t: signed or unsigned? DSF <notavalid@address.here> - 2014-04-21 12:55 -0400
  Re: wchar_t: signed or unsigned? Xavier Roche <xroche@free.fr.NOSPAM.invalid> - 2014-04-21 20:02 +0200
  Re: wchar_t: signed or unsigned? Seungbeom Kim <musiphil@bawi.org> - 2014-04-21 11:07 -0700
    Re: wchar_t: signed or unsigned? Keith Thompson <kst-u@mib.org> - 2014-04-21 11:24 -0700
      Re: wchar_t: signed or unsigned? Seungbeom Kim <musiphil@bawi.org> - 2014-04-21 11:57 -0700
        Re: wchar_t: signed or unsigned? James Kuyper <jameskuyper@verizon.net> - 2014-04-21 15:13 -0400
  Re: wchar_t: signed or unsigned? James Kuyper <jameskuyper@verizon.net> - 2014-04-21 14:31 -0400
  Re: wchar_t: signed or unsigned? Stephen Sprunk <stephen@sprunk.org> - 2014-04-21 15:28 -0500
    Re: wchar_t: signed or unsigned? James Kuyper <jameskuyper@verizon.net> - 2014-04-21 16:48 -0400
      Re: wchar_t: signed or unsigned? Keith Thompson <kst-u@mib.org> - 2014-04-21 14:08 -0700
  Re: wchar_t: signed or unsigned? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-04-22 03:21 -0700
    Re: wchar_t: signed or unsigned? Stephen Sprunk <stephen@sprunk.org> - 2014-04-22 10:48 -0500
    Re: wchar_t: signed or unsigned? Keith Thompson <kst-u@mib.org> - 2014-04-22 09:10 -0700
  Re: wchar_t: signed or unsigned? gordonb.8ql82@burditt.org (Gordon Burditt) - 2014-04-23 03:31 -0500
    Re: wchar_t: signed or unsigned? Stephen Sprunk <stephen@sprunk.org> - 2014-04-25 10:00 -0500
      Re: wchar_t: signed or unsigned? Keith Thompson <kst-u@mib.org> - 2014-04-25 09:00 -0700
        Re: wchar_t: signed or unsigned? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-04-25 10:27 -0700
        Re: wchar_t: signed or unsigned? Stephen Sprunk <stephen@sprunk.org> - 2014-04-25 16:43 -0500

csiph-web