Need Help Getting GCC Working?!?

Discussion of chess software programming and technical issues.

Moderator: Ras

lucasart
Posts: 3243
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: Need Help Getting GCC Working?!?

Post by lucasart »

Steve Maughan wrote:Hi James,

Thanks. They are already in "procs.h". Apologies for the newbie questions but can I ask where you put them so that it compiled? Also, what environment did you use to compile it?

Thanks,

Steve
An inline function, if it is to be used in several translation units, should be declared and defined as "static inline" (plain C) or "inline" (C++) in the header file. This is the only correct and portable way of doing it, as far as I know.

If MSVC accepts things like "extern inline" , or even an inline function declared and defined in bitboard.c but used in another translation unit without even being declared external, then the compiler is at fault and should reject this code with an error message.
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
syzygy
Posts: 5896
Joined: Tue Feb 28, 2012 11:56 pm

Re: Need Help Getting GCC Working?!?

Post by syzygy »

Steve Maughan wrote:The GCC compiler seems to get stuck on

Code: Select all

t_chess_move_type 
enumerated type whoch occurs in

Code: Select all

t_move_record
- I've no idea why!
Because in your code "t_chess_move_type" is not a type, but an enum. The type is "enum t_chess_move_type". To fix it, do this:

Code: Select all

typedef enum { 
	MOVE_CASTLE,
	MOVE_PAWN_PUSH1,
	MOVE_PAWN_PUSH2,
	MOVE_PxPAWN,
	MOVE_PxPIECE,
	MOVE_PxP_EP,
	MOVE_PROMOTION,
	MOVE_CAPTUREPROMOTE,
	MOVE_PIECE_MOVE,
	MOVE_PIECExPIECE,
	MOVE_PIECExPAWN,
	MOVE_KING_MOVE,
	MOVE_KINGxPIECE,
	MOVE_KINGxPAWN
} t_chess_move_type;
Or leave the enum definition as it is and add a line:

Code: Select all

typedef enum t_chess_move_type t_chess_move_type;
Now you can use both "enum t_chess_move_type" and just "t_chess_move_type". Not very pretty, though.

Same with your t_move_list: in your code it is a struct, not a type. It seems your code sometimes has "struct t_move_list" and sometimes "t_move_list" as a type.

It seems C++ allows this kind of sloppiness... I did not know that.
The problem "disappears" if you compile with g++ instead of gcc.
User avatar
Steve Maughan
Posts: 1315
Joined: Wed Mar 08, 2006 8:28 pm
Location: Florida, USA

Re: Need Help Getting GCC Working?!?

Post by Steve Maughan »

Hi Ronald,

Big Aha!!

Many thanks - I'll give it a try. This could be the missing key!

Thanks again,

Steve
jundery
Posts: 18
Joined: Thu Mar 14, 2013 5:57 am

Re: Need Help Getting GCC Working?!?

Post by jundery »

lucasart wrote: An inline function, if it is to be used in several translation units, should be declared and defined as "static inline" (plain C) or "inline" (C++) in the header file. This is the only correct and portable way of doing it, as far as I know.

If MSVC accepts things like "extern inline" , or even an inline function declared and defined in bitboard.c but used in another translation unit without even being declared external, then the compiler is at fault and should reject this code with an error message.
"extern inline" is defined by the standard to mean string literals will refer to the same object (in a paraphrasing of their legalese IIRC). So is perfectly legal, the issue comes when linker gets involved.
mar
Posts: 2674
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: Need Help Getting GCC Working?!?

Post by mar »

Steve Maughan wrote: The shift were intended for pawn moves. There is no data loss since there are never any pawns on the first or eighth row.
You are shifting to_square (unsigned char), not Square64[to_square], I guess you should check braces. (The compiler is usually right when it shows a warning :)
Can I ask what GCC IDE / environment did you use to compile it? Did it start searching after typing "testperft"?
I simply installed mingw from sourceforge, (it's 4.7.x I think). And simply compiled it using g++. It should work, because your code is not ANSI C compliant, but it compiles fine as C++ (I suggest you either fix it or rename sources to .cpp or .cc)
testperft worked, except that it crashed after several seconds.
User avatar
Steve Maughan
Posts: 1315
Joined: Wed Mar 08, 2006 8:28 pm
Location: Florida, USA

Re: Need Help Getting GCC Working?!?

Post by Steve Maughan »

Hi Martin,
mar wrote: You are shifting to_square (unsigned char), not Square64[to_square], I guess you should check braces. (The compiler is usually right when it shows a warning :)
You were right! It was a bug. It should have been a simple -8 and +16 - not a shift. Thanks!
I simply installed mingw from sourceforge, (it's 4.7.x I think). And simply compiled it using g++. It should work, because your code is not ANSI C compliant, but it compiles fine as C++ (I suggest you either fix it or rename sources to .cpp or .cc)
testperft worked, except that it crashed after several seconds.
If it crashes then that's not good. I'm getting closer to having it compile myself in gcc.

Thanks again,

Steve
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: Need Help Getting GCC Working?!?

Post by Evert »

syzygy wrote:Same with your t_move_list: in your code it is a struct, not a type. It seems your code sometimes has "struct t_move_list" and sometimes "t_move_list" as a type.

It seems C++ allows this kind of sloppiness... I did not know that.
Indeed, it's one of the "gotcha"'s of C vs C++.

Note that MSVC is really a C++ compiler (rather than a C/C++ compiler), so it accepts things like this.