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


Groups > comp.lang.c > #43244

Re: wchar_t: signed or unsigned?

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.lang.c
Subject Re: wchar_t: signed or unsigned?
Date 2014-04-21 14:31 -0400
Organization Self
Message-ID <535563FD.8010900@verizon.net> (permalink)
References <4cial9tecgiks7ov2q3c1oo53492kvf3ti@4ax.com>

Show all headers | View raw


On 04/21/2014 12:55 PM, DSF wrote:
> Hello, group!
> 
>   Is wchar_t signed or unsigned?

The C standard does not specify, so any code you write that needs to be
portable should be written to deal with either possibility. Check the
value if WCHAR_MIN #defined in <stdint.h>. If it's 0, wchar_t is unsigned.

>  Is it different in C++ than in C?

No.

>   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.

That's what wint_t is for - though it could also be unsigned. WEOF is
required to have the type wint_t, so it shouldn't be a problem.

>   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.

It's not Unicode itself that matters, it's the particular encoding of
Unicode. Windows used to use UCS-2, and now uses UTF-16, both of which
use all 16 bits. However, there's a lot of applications that could
afford to ignore values for which the high-order bit is set.

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