delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1998/09/22/16:13:54

From: DJ Delorie <dj AT delorie DOT com>
Subject: Re: some unusual errors
22 Sep 1998 16:13:54 -0400 :
Message-ID: <36080502.41C6@delorie.com>
References: <9809211418 DOT AA12875 AT vviuh221 DOT vvi DOT com> <199809212009 DOT NAA00026 DOT cygnus DOT gnu-win32 AT aleph DOT ssd DOT hal DOT com>
Mime-Version: 1.0
X-Mailer: Mozilla 3.0 (X11; I; IRIX 5.3 IP22)

J. J. Farrell wrote:
> isspace() is prototyped as isspace(int); if the caller
> were using the function version, then the prototype would
> be effective, and the char would have been silently and
> correctly widened to an int.

No, the char would have been silently and INcorrectly
widened to a *signed* int, resulting in a range of values of
-128..127.  That is not the legal range of values for the
is*() functions.

The legal range of values for is*() is 0..255 and EOF.  The
automatic widening of a [default signed] char results in
signed int values in the range -128..127.  You cannot rely
on the automatic widening to give correct results.

On a side note, using a signed char as the input makes it
impossible to tell the difference between character 255 and
the traditional EOF value of -1, as both have the same bit
pattern (0xff) when stored in a signed char variable.

Because there are 257 legal parameter values for is*(), an
8-bit variable is simply too small to represent them without
loss or inaccuracy.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019