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


Groups > comp.lang.c > #3243

Re: Return value for error

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: Return value for error
Date 2011-05-04 17:54 -0700
Organization None to speak of
Message-ID <lnzkn2rmoz.fsf@nuthaus.mib.org> (permalink)
References (1 earlier) <ipol8c$ohd$1@dont-email.me> <lnaaf3vc77.fsf@nuthaus.mib.org> <c24039e1-19f0-41f5-8b24-4a645ed11004@24g2000yqk.googlegroups.com> <lnoc3itrkz.fsf@nuthaus.mib.org> <6a2107db-6e19-41a8-aa82-616cc2caa6aa@c41g2000yqm.googlegroups.com>

Show all headers | View raw


"Kleuskes & Moos" <kleuske@xs4all.nl> writes:
> On May 4, 5:26 pm, Keith Thompson <ks...@mib.org> wrote:
[...]
>> Well, sort of.  The argument of the is*() function is an int,
>> but its value is required to be representable as an unsigned char
>> or to be equal to EOF.  The standard *could* have specified some
>> kind of error handling for isalpha(UCHAR_MAX + 1), but instead it
>> just says the behavior is undefined.  Similarly, the behavior of
>> feof(FILE*(NULL)) is undefined.
>
> Aye, it could have introduced a check, and it might have ordained
> array-bounds-checking, too, but the fact of the matter is it doesn't.
> and it seems aginst the spirit of C, too. Besides, returning false for
> isalpha(65535) is a very reasonable implementation of that particular
> bit of undefined behavior and I suspect most compilers will do.

In my experience, at least some implementations define macros for
the is*() functions, macros that work by indexing into arrays.
isalpha(65535) will go well outside the bounds of the array,
with unpredictable results.  (At least one implementation I've
seen defensively allows for small negative arguments, so (signed)
char arguments work as they should, even though the standard doesn't
require them to.  But you shouldn't depend on that.)

[...]

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

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


Thread

Return value for error pozz <pozzugno@gmail.com> - 2011-05-03 01:31 -0700
  Re: Return value for error jacob navia <jacob@spamsink.net> - 2011-05-03 10:46 +0200
  Re: Return value for error Ike Naar <ike@otaku.freeshell.org> - 2011-05-03 09:04 +0000
    Re: Return value for error Ian Collins <ian-news@hotmail.com> - 2011-05-03 21:19 +1200
  Re: Return value for error James Kuyper <jameskuyper@verizon.net> - 2011-05-03 06:26 -0400
    Re: Return value for error Keith Thompson <kst-u@mib.org> - 2011-05-03 12:03 -0700
      Re: Return value for error "Kleuskes & Moos" <kleuske@xs4all.nl> - 2011-05-04 05:15 -0700
        Re: Return value for error Keith Thompson <kst-u@mib.org> - 2011-05-04 08:26 -0700
          Re: Return value for error "Kleuskes & Moos" <kleuske@xs4all.nl> - 2011-05-04 17:08 -0700
            Re: Return value for error Keith Thompson <kst-u@mib.org> - 2011-05-04 17:54 -0700
              Re: Return value for error "Kleuskes & Moos" <kleuske@xs4all.nl> - 2011-05-05 12:03 -0700
  Re: Return value for error James Dow Allen <jdallen2000@yahoo.com> - 2011-05-03 03:45 -0700
    Re: Return value for error Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-05-03 20:50 +0000
  Re: Return value for error pete <pfiland@mindspring.com> - 2011-05-03 07:50 -0400
    Re: Return value for error Keith Thompson <kst-u@mib.org> - 2011-05-03 12:04 -0700
  Re: Return value for error Martin Ambuhl <mambuhl@earthlink.net> - 2011-05-03 07:59 -0400
  Re: Return value for error Mark Storkamp <mstorkamp@yahoo.com> - 2011-05-03 08:46 -0500
  Re: Return value for error Stephen Sprunk <stephen@sprunk.org> - 2011-05-03 10:13 -0500
    Re: Return value for error William Ahern <william@wilbur.25thandClement.com> - 2011-05-03 13:08 -0700
  Re: Return value for error Kenneth Brody <kenbrody@spamcop.net> - 2011-05-03 13:23 -0400
    Re: Return value for error Peter Nilsson <airia@acay.com.au> - 2011-05-03 16:01 -0700
    Re: Return value for error Nobody <nobody@nowhere.com> - 2011-05-05 07:21 +0100
      Re: Return value for error Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-05-05 15:13 +0100
        Re: Return value for error Nobody <nobody@nowhere.com> - 2011-05-06 03:51 +0100
          Re: Return value for error James Kuyper <jameskuyper@verizon.net> - 2011-05-05 23:38 -0400
      Re: Return value for error Keith Thompson <kst-u@mib.org> - 2011-05-05 08:44 -0700
        Re: Return value for error Seebs <usenet-nospam@seebs.net> - 2011-05-05 20:49 +0000
          Re: Return value for error Keith Thompson <kst-u@mib.org> - 2011-05-05 14:10 -0700
            Re: Return value for error Seebs <usenet-nospam@seebs.net> - 2011-05-06 00:26 +0000
  Re: Return value for error Keith Thompson <kst-u@mib.org> - 2011-05-03 12:09 -0700

csiph-web