* Problem with strtol() on ULTRIX 4.2
@ 1993-02-08 19:59 Gregory Larkin
1993-02-08 23:47 ` Alan Watson
0 siblings, 1 reply; 2+ messages in thread
From: Gregory Larkin @ 1993-02-08 19:59 UTC (permalink / raw)
Hi there,
I am having a problem with the way that strtol() works
on a Decstation 5000 running Ultrix 4.2.
On the Sparcstation, strtol() yields these results:
strtol("7fffffff", (char **)NULL, 16) = 2147483647
strtol("80000000", (char **)NULL, 16) = -2147483648
strtol("ffffffff", (char **)NULL, 16) = -1
However, on the Decstation, strtol() cannot yield
negative numbers.
On the Dec:
strtol("7fffffff", (char **)NULL, 16) = 2147483647
strtol("80000000", (char **)NULL, 16) = 2147483647
strtol("ffffffff", (char **)NULL, 16) = 2147483647
Should I be using something other than strtol() on the Dec
to get it to behave like the Sun does? Is this a
C library bug on Ultrix?
Thanks for any help!
--
Greg Larkin, Software Engineer, Waveform Analysis
Viewlogic Systems, Inc. Marlboro, MA 01752
greg@Viewlogic.COM
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: Problem with strtol() on ULTRIX 4.2
1993-02-08 19:59 Problem with strtol() on ULTRIX 4.2 Gregory Larkin
@ 1993-02-08 23:47 ` Alan Watson
0 siblings, 0 replies; 2+ messages in thread
From: Alan Watson @ 1993-02-08 23:47 UTC (permalink / raw)
In article <1993Feb8.195943.23775@viewlogic.com> greg@mobius.viewlogic.com (Gregory Larkin) writes:
>On the Sparcstation, strtol() yields these results:
>
>strtol("7fffffff", (char **)NULL, 16) = 2147483647
>strtol("80000000", (char **)NULL, 16) = -2147483648
>strtol("ffffffff", (char **)NULL, 16) = -1
>
>On the Dec:
>
>strtol("7fffffff", (char **)NULL, 16) = 2147483647
>strtol("80000000", (char **)NULL, 16) = 2147483647
>strtol("ffffffff", (char **)NULL, 16) = 2147483647
From the ISO standard (7.10.1.5):
The strtol 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, LONG_MAX or LONG_MIN is
returned (according to the sign of the value), and the value of the
macro ERANGE is stored in errno.
The Sun implementation clearly does not conform to the ISO standard, but
the DEC implementation does (assuming it correctly sets errno). I don't
know if either of them actually claim conformance.
You can achieve the behaviour of the Sun function by using strtoul and
mapping anything above LONG_MAX to negative numbers.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1993-02-08 23:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1993-02-08 19:59 Problem with strtol() on ULTRIX 4.2 Gregory Larkin
1993-02-08 23:47 ` Alan Watson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox