[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Code "optimization" (?)



Hi,

I was just looking into the code and I came across a function itoa 
(src/common/misc.cpp) which converts decimal number to a string. Once 
upon a time I even used it in my game (!). Some time ago I realized 
that it could be written as:

#include <stdio.h>

char *itoa(int n, char *buf) {
	sprintf(buf, "%d, n);
	return buf;
}

with (I think) the same functionality. As I'm not that experienced 
programmer I'd like to know which way is faster/smaller/better. This 
way you have to include the stdio and it's faster and easier to write. 
Your way might be faster and/or smaller (when compiled) but I'm not 
sure. What's your opinion?

Andrej
____________________________________
RAMMSTEIN, 22.02.2005 o 20,00, Bratislava Incheba, 
Info: 0904 666 363, http://www.xl.sk