Author: Russell Reagan
Date: 09:26:06 01/21/03
Go up one level in this thread
To add debugging code you can use the preprocessors #if defined #ifdef #ifndef
#elif #else to include certain lines depending on whether you are compiling in
"debug" mode or in "release" mode. You can also add assert()'s. When you run in
debug mode it will be slower, but you are only checking for bugs then so speed
is not important. When you run in release mode, all of the debugging code goes
away automagically. So if you have a function:
int array[64];
__ineline int f(i) {
assert(i < 64);
return array[64];
}
The function should not be any slower than just using the array directly. The
difference is that when you compile in debug mode, the assert goes away (at
least the compiler doesn't see it). You can write your own assert macro if you
want, something like this:
int error (char * exp, char * file, char * line) {
printf("error: %s %s %s\n", exp, file, line);
}
#ifdef DEBUG
#define assert(exp) (void(0))
#else
#define assert(exp) (void)( (exp) || (error("exp", __FILE__, __LINE__)) )
#endif
Then if you want to compile your program in "debug" mode, just add this:
#define DEBUG
If you want to compile for speed, just remove that line, or do:
#undef DEBUG
I don't see much point in bounds checking, unless you are going to write code to
dynamically allocate a new array and copy over the entire contents of the old
array on the fly. If you were going to do that, you might as well use C++ and
use an std::vector.
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.