Author: Pat King
Date: 05:45:30 02/26/03
Go up one level in this thread
On February 25, 2003 at 12:40:18, Uri Blass wrote:
>On February 25, 2003 at 12:31:14, Pat King wrote:
[prior to this Uri and Pat wrote a lot of stuff]
>>>
>>>data.h is varaibles when defs.h is definition.
>>>I learned it from tscp.
>>>
>>>some varaibles are dependent on definition so I need to include defs.h first
>>
>>I would submit that this is a bad feature of tscp.
>
>so what do you think?
>
>Do you suggest to include all the definitions and the external varaibles in the
>same file?
>
>I do not see why it is a problem except the error that I reported and finding
>and fixing the error took me only few minutes.
>
I haven't looked at tscp or at your code, but you seem to be saying that you're
declaring a bunch of variables as extern in a header, with the actual
declaration hidden somewhere in the source. This can be a maintenance problem
because you must remember to change both files. A C technique I have used is to
create a macro, typically called EXTERN or GLOBAL, that translates to extern
most of the time, but in one .c file which includes all .h files using the
macro, it translates to nothing, so the variables are actually instantiated in
this one place. Now a change need only take place in one place, the header. The
downside is that everything that uses any global data will now recompile any
time any other global data changes. Since you don't seem worried by compile
times, this may not be an issue for you, but I no longer use this technique
because of it.
I currently find myselfdoing stuff like
// some header
#ifndef SOME_HEADER
#define SOME_HEADER
class some_class
{
protected:
static int SomeData;
};
#endif
Now if I change SomeData, the compiler will easily find all the places code
needs to be changed. There's no externs to worry about, fewer unneccessary
recompiles. To use SomeData, you must inherit frome some_class, but this is in
the spirit of C++'s strong type checking anyway.
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.