🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #2176

Re: strtoul on negative numbers

#2176
From: T. William Wells
Date: Thu, 01 Oct 1992 07:51
23 lines
1222 bytes
In article <1992Sep30.175835.7972@lucid.com> jss@lucid.com (Jerry Schwarz) writes:
: What is the result of
:
:     strtoul("-2", (char**)0, 10)
:
: The description is clear that the minus sign is allowed.
: The relevant sentence describing the result is.
:
: "If the correct value is outside the range of representable values
: ULONG_MAX is returned ..."
:
: My reading of this is that it requires ULONG_MAX to be returned,
: but others think that -2 is a representable value (equal to
: ULONG_MAX-1) and so ULONG_MAX-1 should be returned.

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.

---
Bill                            { rutgers | decwrl | telesci }!twwells!bill
bill@twwells.com
Technical Details
Message-ID: <BvFn5v.JKK@twwells.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!decwrl!twwells!bill
References: <1992Sep30.175835.7972@lucid.com>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c
Path: arc1-ca.pugleaf.net!sparky!uunet!decwrl!twwells!bill
From: bill@twwells.com (T. William Wells)
Subject: Re: strtoul on negative numbers
Date: Thu, 1 Oct 1992 07:51:29 GMT
Message-ID: <BvFn5v.JKK@twwells.com>
References: <1992Sep30.175835.7972@lucid.com>
Organization: None, Mt. Laurel, NJ
Lines: 23