[comp.std.c] strtodl

scs@avarice.pika.mit.edu (Steve Summit) (07/06/89)

Microsoft's implementation of strtol (or was it strtod?  I
forget) returns, when given the string " x", a 0, with the "end
pointer" argument pointing to the 'x'.  I think this is a bug.
One of the significant advantages that strto[dl] have over ato[fl]
ought to be that you can determine, by comparing the returned end
pointer with the initial string pointer, whether a number was
actually converted and if so, where it ended.  By returning a
pointer which has been stepped over leading whitespace even
though no number was converted, it becomes impossible to
distinguish between the strings " x" and " 0" (without inspecting
the characters yourself, which you shouldn't have to do).  Does
the wording in the standard make the correct behavior in this
case clear?  (For now, I've written my own strtoi, which behaves
as I'd like it to, and also returns ints instead of longs or
doubles.)

                                            Steve Summit
                                            scs@adam.pika.mit.edu

dfp@cbnewsl.ATT.COM (david.f.prosser) (07/06/89)

In article <12458@bloom-beacon.MIT.EDU> scs@adam.pika.mit.edu (Steve Summit) writes:
>Microsoft's implementation of strtol (or was it strtod?  I
>forget) returns, when given the string " x", a 0, with the "end
>pointer" argument pointing to the 'x'.  I think this is a bug.

All of strto{d,l,ul} have the same statement:

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

Thus, if any of these functions are passed the string " x", the character
pointed to by the end pointer should be the space.

Dave Prosser	...not an official X3J11 answer...