itoa'd you so?
levi at cold.org
Sat Sep 22 12:41:10 MDT 2007
Charles Curley <charlescurley at charlescurley.com> writes:
>> > * dividing by a variable instead of an inline constant, usually
>> > slower.
>> Your solution doesn't take 'base' as a paramter, so I can only assume
>> you've defined it as a constant global variable somewher else in your
>> program. In that case, your solution is just as fixed as mine. The
>> modifications to change the base for either are trivial, but require a
> You are correct that base is defined elsewhere; it is a global.
> Again, this is embedded programming. A calling function can set base
> before calling itoa. That's a bit more flexible than adding to your
> lookup array, which will be in ROM at runtime.
My point was that your point of criticism only applied if the global
was also a constant. Otherwise, no constant folding, and you still
divide by a variable. Sure, you don't have to pass a parameter, but
we're getting into ugly optimization territory now. I'd never do that
unless circumstances demanded it. Clean, elegant code wins over
prematurely optimized code.
Make it correct, make it simple, and then, if it's not fast enough,
make it fast with as little compromise to the other two as possible.
Anyway, it's been fun. Thanks to smorrey for posting the question. :)
More information about the PLUG