Oh, and a related word to the wise ..
I just spent an hour debugging a problem with my TCP/IP code and it was a wasted hour. The problem was that in one C++ part I added a new function at the top of the file to print an IP address to a buffer. It was a pretty simple function using sprintf to fill in the buffer. Should be easy, right?
Code:
IpAddr_t is a typedef for unsigned char[4]
char *IP::formatAddress( IpAddr_t a, char *buffer ) {
sprintf( buffer, "%d.%d.%d.%d", a[0], a[1], a[2], a[3] );
return buffer;
}
Well, it wasn't giving output at all.. Turned out to be that the sprintf always returning 0, which means no error, but no bytes written.
After a lot of digging around I figured out that duplicating the sprintf line in the function would work. It just wasn't liking the first sprintf.
After more work I figured out that putting this function at the beginning of the file made my formatAddress function work perfectly, with no kludges:
Code:
void dummyFunc( void ) { puts(""); }
rest of code starts here ...
So what I suspect is happening is that there is a linker error, and that the first call outside of this particular object file isn't being resolved correctly. There is certainly nothing wrong with the code - all I have to do is put that dummy function first, and life is great.
Moral of the story? I like Turbo C++ 3.0 and all of the Turbo C products in general. But they have more bugs than a dog has fleas. I generally avoid the hardcore C++ language features because I've run into other bugs, but this particular bug was a suprise, even for me.