Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: a struct or just a new file ? (C question)

Author: Alessandro Damiani

Date: 10:41:59 07/13/02

Go up one level in this thread


On July 13, 2002 at 08:07:28, Georg v. Zimmermann wrote:

>To further improve the readability of my program I decided to group all clock
>related functions (setting the level, checking whether time is out etc)
>together. Those are using some of the few global variables I have left.
>
>To do that I just created a clockStruct which has
>
>struct clockStruct
>{
>public:
>
>void setLevel(int fixedTime, int fixedDepth, int timeInc, int timeBase);
>int timeToMove();
>[...]
>
>private:
>int timeOnClock[COLORS];
>int timeBase;
>int timeInc;
>
>double clockAtLastMove;
>[...]
>}
>
>Today it occured to me that instead I can just move all clock related functions
>to one file and thus the variables like timeOnClock[COLORS] would have limited
>scope restricted to the clock functions as well.
>
>
>Question now is what you think is the better coding standart ?
>Also, does the compiler care about that at all or is the generated code similar
>? AFAIK the above options only "protect" the variables from bad coding style so
>internally it should not matter. Or does using a struct group the vars closer
>together in memory? If so, is that good (because all those vars are used
>together and are not needed outside the non-time-critical clock functions) or
>bad (because the compiler has less freedom).
>
>Any hints appreciated,
>
>Georg
>
>PS.
>I need an utility that can strip code off all lines between
>#ifdef GARBAGE
>#endif
>if GARBAGE is undefined. Anyone know of one ? That would be great.

Since I started rewriting my engine in a object oriented way I use a module
called TimeManager for time related tasks. In C I therefore have two files:

   TimeManager.c
   TimeManager.h

Each module in my engine has a public init() method that is called from the main
module at startup.

Public methods have the prefix "<module name>_" to simulate OO calls. So the
init() method in the TimeManager module is called by the following statement:

   TimeManager_init();

I accept the drawback that inside a module calls to public methods require the
prefix. The benefit is high.

Although I didn't reply to all your questions I hope this helps.

Viel Spass! :)

Alessandro



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.