From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,fdc1a44e88d600ef X-Google-Attributes: gid1164f8,public X-Google-ArrivalTime: 1993-02-08 15:47:45 PST Newsgroups: comp.sys.dec Path: sparky!uunet!ferkel.ucsb.edu!taco!gatech!swrinde!cs.utexas.edu!usc!sol.ctr.columbia.edu!sal.wisc.edu!alan From: alan@sal.wisc.edu (Alan Watson) Subject: Re: Problem with strtol() on ULTRIX 4.2 Message-ID: <1993Feb8.234745.6382@sal.wisc.edu> Organization: Space Astronomy Lab, Madison WI References: <1993Feb8.195943.23775@viewlogic.com> Date: Mon, 8 Feb 1993 23:47:45 GMT 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.