Could someone help me out here? In VC++ 6.0, in some apps im making, GL or not, itoa crashes whenever called! For instance, if I were to compile and run the following in one such project:
char *num = itoa(50, NULL, 10);
it would just lock up, in both debug and release builds. Any idea whats going on?
What should itoa be doing? If you pass a pointer to it, it can’t allocate memory for it. The only possibility would be that you pass a pointer to a pointer.
Originally posted by Kranomano: Ok. char *whatever = itoa(num, NULL, 10) is what ive used since the beginning of time without trouble… guess I’ll switch. Thanks.
Then you’ve been lucky since the beginning of time. itoa needs you to give it space to use. It does not dynamically allocate the memory for you and that’s what it would have to do if you were to use it that way. Think about it for a second. If you didn’t specify the memory, where in memory is it going to set that pointer to point to?
One of the keys to mastering C/C++ is understanding how memory is used.
Yeah I’ve been understanding that more and more lately. I’ve been programming with C++ for about 2 years now, on and off, and it hasnt been until recently that I’ve had to deal with memory managment. That’s mainly because what I was doing before was a hell of a lot less advanced than OpenGL programming.