[PATCH] itoa

Freddie Chopin freddie_chopin@op.pl
Mon Dec 8 18:12:00 GMT 2014

On 12/08/2014 06:17 PM, Corinna Vinschen wrote:
> What other platforms?

Well, avr-libc has it ( 
). msp430-libc too ( 
). This function is really popular among "small" targets. It is even 
mentioned by online C++ reference - 

The interface is not really safe, but it could be made a bit better, but 
not "standard" (yeah, like there is a standard of non-standard functions 
(; ) - the returned value "char*" could be used to report a problem (by 
returning NULL instead of pointer to string) with following things:
- invalid base,
- nullptr passed as string.

This of course leaves the most problematic thing - the size of buffer... 
We could always invent a safer alternative - itoa_np(), utoa_np(). It 
wouldn't be such a bad idea, given how useful such functions are (;

char* itoa_np(int, char*, size_t, int) ?
or maybe
int itoa_np(int, char*, size_t, int) ?

Here is a first function I'd send a patch for, which would replace 
fiprintf() with write() and itoa() - 
. In my embedded project one of first things I add to the project is an 
override of __assert_func(), because 20kB (including dynamic allocation) 
for such simple functionality is just a bit too much...


More information about the Newlib mailing list