🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1529

Re: strtoul("-10", ...)

#1529
From: Larry Jones
Date: Thu, 26 Jul 1990 13:40
37 lines
2252 bytes
In article <GAFTER.90Jul24163928@m2.csc.ti.com>, gafter@m2.csc.ti.com (Neal M Gafter) writes:
> I have implemented the ANSI library function strtoul() [4.10.1.6] and
> had a little problem interpreting the standard.  To quote:
> 
> 	If the subject sequence begins with a minus sign, the value
> 	resulting from the conversion is negated.
> and
> 	If the correct value is outside the range of representable
> 	values, ULONG_MAX is returned, and the value of the macro
> 	ERANGE is stored in errno.
> 
> Discounting the possibility that X3J11 intended errno never to be set
> to ERANGE by strtoul(), I assumed X3J11 meant the range
> [0..ULONG_MAX].  I presumed the sentence about the minus sign was to
> allow the string "-0" and to recognize (as errors) other negative
> numbers.  Thus, I assumed any string representing a negative number
> should cause errno to be set to ERANGE and strtoul() to return
> ULONG_MAX.

This was discussed at the last meeting.  The (unanimous, as I recall)
sense of the committee was that the intended meaning of the above is
that the digit sequence is to be converted to an unsigned long.  If
the value of the digit sequence is greater than ULONG_MAX, then the
unsigned long is set to ULONG_MAX and errno is set.  If there was a
leading minus sign, the unsigned long is negated according to the
rules for negation of unsigned values.  The resulting unsigned long
value is then returned.

I don't believe that this was a formal interpretation.  If you want
one, send a request to the X3 Secretariat, CBEMA.
----
Larry Jones                         UUCP: uunet!sdrc!thor!scjones
SDRC                                      scjones@thor.UUCP
2000 Eastman Dr.                    BIX:  ltl
Milford, OH  45150-2789             AT&T: (513) 576-2070
"This probably just goes to show something, but I sure don't know what."
-Calvin
Technical Details
Message-ID: <117@thor.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!sdrc!thor!scjones
References: <GAFTER.90Jul24163928@m2.csc.ti.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!sdrc!thor!scjones
From: scjones@thor.UUCP (Larry Jones)
Newsgroups: comp.std.c
Subject: Re: strtoul("-10", ...)
Message-ID: <117@thor.UUCP>
Date: 26 Jul 90 13:40:31 GMT
References: <GAFTER.90Jul24163928@m2.csc.ti.com>
Distribution: comp
Organization: SDRC, Cincinnati
Lines: 37