Article View: comp.std.c
Article #2173Re: strtoul on negative numbers
From: Norman Diamond
Date: Thu, 01 Oct 1992 02:38
Date: Thu, 01 Oct 1992 02:38
31 lines
2150 bytes
2150 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 description is schizophrenic. ANSI 4.10.1.6, page 153 line 20:
"a subject sequence resembling an unsigned integer"
(in contrast to strtol, ANSI 4.10.1.5, page 152 lines 23 to 24:
"a subject sequence resembling an integer").
But later, page 153 lines 25 and 28 and 31 allow a plus or minus sign.
Lines 22 to 23: "Then it attempts to convert the subject sequence to an
unsigned integer, and returns the result" (again in contrast to strtol,
which omits the word "unsigned"). So do negation and an implied cast to
unsigned occur during this conversion?
Lines 40 to 41: "If the subject sequence begins with a minus sign, the
value resulting from conversion is negated." So does negation occur
after conversion is finished? Is there no implied cast to unsigned?
>The relevant sentence describing the result is.
>"If the correct value is outside the range of representable values
>ULONG_MAX is returned ..."
Uh yeah, but which is the "correct" value?
I think that section 4.10.1.6 seems both self-contradictory and ambiguous,
so it is impossible to fully conform, but possible in several ways to
partially conform.
--
Norman Diamond diamond@jit081.enet.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.
"Yeah -- bad wiring. That was probably it. Very bad."
Technical Details
Message-ID:
<1992Oct1.023845.12314@nntpd.lkg.dec.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!ames!decwrl!deccrl!news.crl.dec.com!pa.dec.com!nntpd2.cxo.dec.com!nntpd.lkg.dec.com!jit345.bad.jit.dec.com!diamondReferences:
<1992Sep30.175835.7972@lucid.com>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!ames!decwrl!deccrl!news.crl.dec.com!pa.dec.com!nntpd2.cxo.dec.com!nntpd.lkg.dec.com!jit345.bad.jit.dec.com!diamond From: diamond@jit345.bad.jit.dec.com (Norman Diamond) Subject: Re: strtoul on negative numbers Message-ID: <1992Oct1.023845.12314@nntpd.lkg.dec.com> Sender: usenet@nntpd.lkg.dec.com (USENET News System) Reply-To: diamond@jit.dec.com (Norman Diamond) Organization: Digital Equipment Corporation Japan , Tokyo References: <1992Sep30.175835.7972@lucid.com> Date: Thu, 1 Oct 1992 02:38:45 GMT Lines: 31