Re: style question,itoa

Frank Cusack schrieb:
Dont intend to change that. I´m comfortable with that.
That's puzzling.
Not really. I dont like using arrays on the stack unless i can know
for certain they cant overflow. But thats my personal style.

Yes but in this case you do know they can't overflow. An int is at
most 11 chars.
Since i dont know if int can be 64bit i decided to play save there. (18bytes suffice for the number +1 for sign and +1 for the null termination).
But your statement is irrelevant anyway. If i have a pointer to stack space array (or offset into an array) i have to perform additional range checks.

Having the caller pass in a buffer also doesn't REQUIRE that that buffer
be on the stack. But I assume you are optimizing for speed (?) since
you aren't simply using sprintf(). In which case you probably would do
better to use the stack.
Yes, i do optimize for speed, as much as possible, without sacrificing robustness. And as i said i prefer pointers to arrays. Ok, so malloc/free add a larger overhead than range checks, but the worst case scenarios for heap corruption arent nearly as bad as for stack corruption.

Lastly, when the caller has to free() something, it's nicer if the
caller actually has to malloc() it as well.
Call me lazy if you wish, i prefer writing a line less ;)
It helps you read the
code better.
Good to know you know that i will have an easier time reading my code when using functions i wrote that behave as i wanted to. I didnt know that yet.