Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: question about errors when I change my C code to C++

Author: Heiner Marxen

Date: 09:56:45 02/26/03

Go up one level in this thread


On February 26, 2003 at 08:44:40, Pat King wrote:

>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.

Therefore, the C file that implements the variable really should
include the H file with the extern declaration.
Every "module" shall include its own export interface.
[ In fact, it should be the very first include there. ]

Then the compiler will check the consistency between both of them.

>                                               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.

Personally I do not do it that way.
Theoretically this is a good way to do it (write it once),
but practically there are problems (initial values, grouping with code).
Also, I tend to not have many global variables.

Cheers,
Heiner



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.