[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: strtonum(3) from OpenBSD?
Tonnerre LOMBARD wrote:
> On Fri, Jun 26, 2009 at 01:15:11AM -0400, James K. Lowden wrote:
> > I don't understand why atoi() keeps getting reinvented when we have a
> > completely standard, easily extended alternative: sscanf(3).
> I will simply suppose you are kidding here
Not at all. I'm quite serious.
> There's no reason whatsoever to use a string format definition
> which is read and evaluated at runtime if there is no format being
> processed in the first place. Converting a string to some type of
> integer should not require such overhead and error-proneness, especially
> in an operating system which promises speed and flexibility on embedded
I fail to see how sscanf(3) is more error prone than strtonum(). No
matter what, you have to specify -- via the name or the format string --
the format of the input and of the receiving buffer. At least with
sscanf(3) that's *all* you have to do. If that's so terribly difficult
and slow, why is there no inverse for strtol()?
> (Hey, did you know that 26-bit architectures are a bit limited in terms
> of memory, and typically also execution speed?)
What impoverished platform are you referring to that yields a measurable,
*meaningful* performance difference between these functions? How much
improvement/degradation did you observe?
In 1985 I remember we had to make sure strlen(3) and strcpy(3) were
written in assembler to take advantage of the chip's function. Everything
fit in 128 KB of RAM, and the number of processes was strictly limited: 1.
We used puts(3) instead of printf(3) when we could for speed and size
That was probably misplaced then and it's surely misplaced now, unless
you're running on something less powerful than an Intel 8086.
> Also, from the rest of the thread it should be pretty clear what we want
> and what our criteria are.
As I said, I don't understand. The motivation is AIUI to ease porting
applications from other platforms. I have a hard time believing *anyone*
is using strtonum() in some time-critical way. On the contrary, I think
everyone is better off using general-purpose I/O functions. Their code
would be clearer and, yes, less error-prone.
The proliferation of special-purpose functions looks like turd-polishing
to me. I can't wait for 128-bit native integer support, so we can have
yet another round. Yay.
Main Index |
Thread Index |