🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1291

strtoul question

#1291
From: Adam Stoller
Date: Fri, 25 May 1990 13:46
46 lines
2216 bytes
In looking over the specification for strtoul I find myself (as usual:-)
a bit confused.  According to the stanadard (which I've tried to trim to
the essentials and have added emphasis to):


> The strtoul function converts ... nptr to unsigned long int
> representation. First, it decomposes the input string into three parts:
>  ... a subject sequence RESEMBLING AN UNSIGNED INTEGER ... Then, it attempts to
> convert the subject sequence to an unsigned integer ...

> If the value of base is zero, the expected form of the subject sequence
> is that of an integer constant as described in 3.1.3.2, OPTIONALLY
> PRECEDED BY A PLUS OR MINUS SIGN, but not including an integer suffix.
> If the value of BASE is between 2 and 36, the expected form  ...
> OPTIONALLY PRECEDED BY A PLUS OR MINUS SIGN, but not including an
> integer suffix.  ...

> [...]

>  ...  IF THE SUBJECT SEQUENCE BEGINS WITH A MINUS SIGN,
>  THE VALUE RESULTING FROM THE CONVERSION IS NEGATED.  ...

> If the subject sequence is empty or does not have the expected form, no
> conversion is performed; the value of nptr  is stored in the object
> pointed to by endptr, provided that endptr is not a null pointer.

> The strtoul function returns the converted value, if any. If no
> conversion could be performed, zero is returned. 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.

What exactly (if one can use that term) is the strtoul() function
supposed to return when handed a string like "-987654" ?

    a) behave like labs() and return 987654
    b) return 0
    c) return ULONG_MAX
    d) set errno to ERANGE
    e) [b & d]
    f) [c & d]
    g) other - please explain.


Any help in interpreting this is much appreciated.

--fish
Technical Details
Message-ID: <UaLHQb200as9AS60EP@andrew.cmu.edu>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!pt.cs.cmu.edu!andrew.cmu.edu!ghoti+

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!pt.cs.cmu.edu!andrew.cmu.edu!ghoti+
From: ghoti+@andrew.cmu.edu (Adam Stoller)
Newsgroups: comp.std.c
Subject: strtoul question
Message-ID: <UaLHQb200as9AS60EP@andrew.cmu.edu>
Date: 25 May 90 13:46:15 GMT
Organization: Information Technology Center, Carnegie Mellon, Pittsburgh, PA
Lines: 46