strto[dl]

Steve Summit scs at avarice.pika.mit.edu
Thu Jul 6 14:12:59 AEST 1989


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 at adam.pika.mit.edu



More information about the Comp.std.c mailing list