Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: debugging question

Author: Gerd Isenberg

Date: 11:50:24 08/13/03

Go up one level in this thread


On August 13, 2003 at 11:56:38, Uri Blass wrote:

>There are cases when I make changes that are not supposed to change
>a single global varaible(the changes can be only for speed or only some
>preperation for another change because new function that I write may be used
>later in a different way).
>
>I need for debugging purposes a function that put all
>global varaibles to a file and a function that compares
>the content of this file with the content of another
>file that is supposed to be the same.
>
>Is there a simple way to do it or do I need for every global array that I have
>to write a loop and for every varaible to write a special command.
>
>I prefer if there is some general solution(otherwise everytime that I add
>a new global varaible or delete a global varaible I also need to change the
>function).
>
>Uri

Hi Uri,

one solution is to put all globals in one or more structs or classes.
Instead of many globals vars and arrays you declare only one or few "global"
singletons. Some replacement work - but then you may implement some persistance
layer, to read and write it with sizeof(struct) from or to some files.

For debug comparison reasons you may compare these persistant incarnations of
your globals with some file diff tools. At runtime you may use a second set of
these "globals" for degug reasons, with content of a  further saved file. Some
compare functions e.g. implemented as !=operator.

Some ASSERT_GLOBAL and SAVE_GLOBAL - Macros, both with filename as parameter.

Gerd


#ifdef __DEBUG
#define ASSERT_GLOBAL(filename) \
{ \
 theDebugOne.readFrom(filename); \
 if (theRealOne != theDebugOne) \
 {
   // some additional things like pasting FEN or current node "PGN" \
   // to some file or even windows clipboard \
   ASSERT(FALSE); \
 } \
}
#else
#define ASSERT_GLOBAL(filename)
#endif




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.