RE: [Dev-C++] itoa - atoi : another implementation
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <iv...@em...> - 2003-04-02 20:55:03
|
> -----Original Message----- > From: Per Westermark [mailto:pw...@ia...]=20 > Sent: Wednesday, April 02, 2003 10:13 PM > To: Ioannis Vranos > Cc: 'Dev-C++' > Subject: RE: [Dev-C++] itoa - atoi : another implementation=20 >=20 >=20 > You might have been in even more hurry :-) >=20 > How many characters do you allocate if the integer was zero,=20 > or negative? Yes you are right, I forgot the <=3D0 stuff. Well I leave it as an = exercise for home. :) >=20 > And then of course - itoa() with a sprintf() is of very=20 > little use, since > it doesn't solve reentrancy problems, What do you mean. > doesn't support variable number > base, No it doesn't. > and doesn't allow linking without the formatted RTL code. What do you mean. =20 > It isn't even a good optimization of number of source code > characters, since each call MUST be either: > free(itoa(i1)); > which is an expensive NOP instruction, or: It is supposed to be used where free store usage is affordable (almost everywhere these days). No specific constraint requirements were = provided by the OP. > char *p =3D itoa(i1); > use_string(p); > free(p); > which isn't much shorter than > char buf[20]; > sprintf(buf,"%d",i1); > use_string(buf); Yes it isn't. That's why I said itoa() is not needed. =20 > Whith a static buffer in itoa() you get code length improvement > with: > use_string(itoa(i1)); The above is not thread safe (since as I saw you try to embarrass me). = :) You must place a locking mechanism. > and with a semi-standard implementation of itoa you get code length > improvement AND extra number bases: > char buf[30]; > use_string(itoa(i1,buf,3)); // trinary output I do not know any standard or semi-standard impleentation of itoa(). = Even in K&R2 it is not what you are talking about. Ioannis Vranos =20 * Programming pages: http://www.noicys.freeurl.com * Alternative URL: http://run.to/noicys |