markc@com2serv.c2s.mn.org (Mark H. Colburn) (12/15/89)
I have a question about the wording of the descriptions for the strtol and strtoul library calls in the ANSI draft standard (I have the October 31, 1988 version): where should endptr point to if an error occurs? For example, given the following code: unsigned long foo; char *ptr; foo = strtoul("-12345", &ptr, 0); where would ptr point to? The call should return ULONG_MAX with errno set to ERANGE, but does *ptr = '-' or '\0' (end of string) or is it indeterminate? It looks as if it should point to '\0', but... Mark H. Colburn mark@minnetech.mn.org Open Systems Architects, Inc.
chris@mimsy.umd.edu (Chris Torek) (12/16/89)
In article <3233@com50.C2S.MN.ORG> markc@com2serv.c2s.mn.org (Mark H. Colburn) writes: > unsigned long foo; > char *ptr; > > foo = strtoul("-12345", &ptr, 0); >... where would ptr point to? The call should return ULONG_MAX with errno >set to ERANGE, but does *ptr = '-' or '\0' (end of string) or is it >indeterminate? It looks as if it should point to '\0', but... It should return (unsigned long)-12345, which is typically either 53191 or 4294954951, and leave *ptr=='\0'. For foo = strtoul("340282366920938463463374607431768211456", &ptr, 0); which *is* too big (unless you have 128 bit `long's), it should return ULONG_MAX, errno==ERANGE, and *ptr=='\0'. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@cs.umd.edu Path: uunet!mimsy!chris
chris@mimsy.umd.edu (Chris Torek) (12/17/89)
In article <21305@mimsy.umd.edu> I wrote: >strtoul("340282366920938463463374607431768211456", &ptr, 0); >... *is* too big (unless you have 128 bit `long's) .... Oops, that should be `greater than 128 bit'. The number in double quotes there is $2^{128}$ (or $2 sup 128$ for troff folks), which is just barely too big for a 128 bit unsigned long. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@cs.umd.edu Path: uunet!mimsy!chris