itoa'd you so?

Levi Pearson levi at
Fri Sep 21 16:19:00 MDT 2007

Dave Smith <dave at> writes:
> My version skips the strcat() at the end of itoa() in favor of just
> returning a char* that points at where my itoa() put the string in the
> specified buffer. The caller can then know where to find the int. It
> saves a bit of time, but at the slight cost of a somewhat bulky API.

This is probably okay if you really need the extra performance, but it
makes the memory management awkward.  You've now got to keep track of
the original buffer as well as the pointer to where the string begins
within it.  If you don't realize this and call free on the point where
the string begins, you're likely to have trouble.

I prefer the K&R approach of building the string backwards and
reversing it afterward.


More information about the PLUG mailing list