This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] itoa


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

Well, avr-libc has it ( http://www.nongnu.org/avr-libc/user-manual/group__avr__stdlib.html#gaa571de9e773dde59b0550a5ca4bd2f00 ). msp430-libc too ( http://sourceforge.net/p/mspgcc/msp430-libc/ci/master/tree/src/stdlib/xtoa.inc ). This function is really popular among "small" targets. It is even mentioned by online C++ reference - http://www.cplusplus.com/reference/cstdlib/itoa/

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() - https://sourceware.org/git/?p=newlib.git;a=blob;f=newlib/libc/stdlib/assert.c;h=135bf15194bb0556597fc7e6cf4b3aa28224acf2;hb=1e3bf58dc5974a09ffe1be2609108cb6ff4a3e92 . 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...

Regards,
FCh


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]