compile order ms vs c++

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Re: C++ classes for enumeration scalars

Post by sje »

Code: Select all

bb.h:
------

#ifndef includebb
#define includebb

class BB {blah blah blah};

#endif


cons.h:
-------

#ifndef includecons
#define includecons

extern const BB bb0;
extern const BB bb1;

#endif


cons.cpp:
-----------

#include "bb.h"

const BB bb0 = &#40;1ull << 0&#41;;
const BB bb1 = &#40;1ull << 1&#41;;


everywhere else&#58;
-------------------

#include "bb.h"
#include "cons.h"

...

User avatar
Desperado
Posts: 879
Joined: Mon Dec 15, 2008 11:45 am

Re: C++ classes for enumeration scalars

Post by Desperado »

2. Put static const variables in bitboard.hpp: The relatively best solution. But puts instances of the constants in every module, so wastes memory.
This is the solution i use now...

Nice to see, that last but not least it is not so trivial as some of you
mentioned at the beginning of the thread.(as i followed correctly
it has been discussed on multiple definitions,memory usage and interaction of headers and also pro/con about using enum/cons)

(So with respect to the people who advised me to read a c++ book for beginners, first think then post)
User avatar
Onno Garms
Posts: 224
Joined: Mon Mar 12, 2007 7:31 pm
Location: Bonn, Germany

Re: C++ classes for enumeration scalars

Post by Onno Garms »

sje wrote: (code)
This is solution number 1 (with parts of bitboard.?pp moved to cons) with the drawback I already pointed out.
User avatar
Desperado
Posts: 879
Joined: Mon Dec 15, 2008 11:45 am

Re: C++ classes for enumeration scalars

Post by Desperado »

1.
Using class-keyword is just a (elegant,propper,legal) workaround
solution in the end.
Because a global constant definition should work simple by its definition itself, like all other shared data. But it works and may satisfiy.

2.
it is simply not possible with "basics"(just definition and declarations) to keep (also onno mentioned)
the following condition list.

- typesafe data
- no multiple definition or memory usage
- global scope
- possible inlining

the closest i reached with basics to hold the conditions
was (i know i repeat this).

Code: Select all


//the definition may me done in a modul you like
----------------------------------------------------------

#ifdef USE_DEFINITION

	extern const type c_name = value;

#endif

//all other moduls will use this
----------------------------------------

#ifndef USE_DECLARATION
	
	#define USE_DECLARATION

	extern const type c_name;

#endif

RESULT:

- typesafe data -> OK
- no multiple definition or memory usage ->OK
- global scope -> OK
- possible inlining ->(OK) BUT NOT GUARANTEED

At the end anybody has to decide between
- or for a (natural c++ class,any other) workaround,
- or using static const each modul
- or something like this.
- or some other solution

So, and now one more of my final questions (:-)).

Should it not easily be like this: 1x gl const def and X x gl const decl. ?