🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #2193

Re: strtoul on negative numbers

#2193
From: Phil Howard
Date: Fri, 02 Oct 1992 21:01
17 lines
1232 bytes
bill@twwells.com (T. William Wells) writes:

>The definition for strtoul says that one converts the number (to
>an unsigned long) ignoring the minus sign and then negates it.
>Negation is defined for all values of an unsigned type, resulting
>in ULONG_MAX+1-x, where x is 2, for this case.

I take it that your interpretation is saying that strtoul() is supposed
to return an unsigned integer with the value ULONG_MAX+1-x whenever an
input number has the form of a "-" followed by a properly formed unsigned
quantity.

If the representation given is outside of the range of ULONG_MAX (the part
following the "-", not including it) then ULONG_MAX would be returned.  But
what if such an out of range number is preceeded by a "-"?  Do we return
the value ULONG_MAX+1-ULONG_MAX (which would be just 1) or do we return the
value ULONG_MAX?
Technical Details
Message-ID: <BvIIEE.74J@ux1.cso.uiuc.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!caen!sdd.hp.com!ux1.cso.uiuc.edu!phil
References: <1992Sep30.175835.7972@lucid.com> <BvFn5v.JKK@twwells.com>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c
Path: arc1-ca.pugleaf.net!sparky!uunet!caen!sdd.hp.com!ux1.cso.uiuc.edu!phil
From: phil@ux1.cso.uiuc.edu (Phil Howard)
Subject: Re: strtoul on negative numbers
Message-ID: <BvIIEE.74J@ux1.cso.uiuc.edu>
Organization: University of Illinois at Urbana
References: <1992Sep30.175835.7972@lucid.com> <BvFn5v.JKK@twwells.com>
Date: Fri, 2 Oct 1992 21:01:12 GMT
Lines: 17