Strange bug - GCC does not detect existing member of board

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: Strange bug - GCC does not detect existing member of boa

Post by lucasart »

Rein Halbersma wrote:Pro tip: http://sscce.org/ Just going through these steps yourself before posting, will solve most problems on their own because you will identify the problem.
very good advice!
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
Rein Halbersma
Posts: 741
Joined: Tue May 22, 2007 11:13 am

Re: Strange bug - GCC does not detect existing member of boa

Post by Rein Halbersma »

lucasart wrote:
Rein Halbersma wrote:Pro tip: http://sscce.org/ Just going through these steps yourself before posting, will solve most problems on their own because you will identify the problem.
very good advice!
thanks. it's common practice at Stackoverflow. I think it would be great if there would be a ChessProgramming site over there.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Strange bug - GCC does not detect existing member of boa

Post by bob »

was going to suggest a couple of things to try, but it seems you have already fixed the problem...

I've not seen any version of gcc I use create any "pre-compiled headers" however...
Rein Halbersma
Posts: 741
Joined: Tue May 22, 2007 11:13 am

Re: Strange bug - GCC does not detect existing member of boa

Post by Rein Halbersma »

bob wrote:was going to suggest a couple of things to try, but it seems you have already fixed the problem...

I've not seen any version of gcc I use create any "pre-compiled headers" however...
https://gcc.gnu.org/onlinedocs/gcc/Prec ... aders.html

It is primarily used in C++ to decrease compilation times of the Standard Library headers (which are templates)
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Strange bug - GCC does not detect existing member of boa

Post by bob »

Rein Halbersma wrote:
bob wrote:was going to suggest a couple of things to try, but it seems you have already fixed the problem...

I've not seen any version of gcc I use create any "pre-compiled headers" however...
https://gcc.gnu.org/onlinedocs/gcc/Prec ... aders.html

It is primarily used in C++ to decrease compilation times of the Standard Library headers (which are templates)
Notice my "gcc" and not "g++". I'm not a big c++ fan myself. I could see why c++ files might usefully be precompiled and remembered, it takes 1.5x longer to compile egtb.cpp (6K lines) than it does the rest of the crafty source (almost 40K lines). That's roughly 10x slower.
Rein Halbersma
Posts: 741
Joined: Tue May 22, 2007 11:13 am

Re: Strange bug - GCC does not detect existing member of boa

Post by Rein Halbersma »

bob wrote:
Rein Halbersma wrote:
bob wrote:was going to suggest a couple of things to try, but it seems you have already fixed the problem...

I've not seen any version of gcc I use create any "pre-compiled headers" however...
https://gcc.gnu.org/onlinedocs/gcc/Prec ... aders.html

It is primarily used in C++ to decrease compilation times of the Standard Library headers (which are templates)
Notice my "gcc" and not "g++". I'm not a big c++ fan myself.
I know you are a C guy. That's why you haven't seen precompiled headers before, because the C standard library is already precompiled. :-)

For C++, there is also some precompiled stuff (iostreams and the rest of the runtime system), but the algorithms/containers stuff are templates and defined in headers. Same for most of Boost. E.g. for Visual C++, there is this stdafx.h header that contains all C++ standard library headers in precompiled form to save people from recompiling them over and over. C++ people have gone to great lengths to reduce compile times (concatenating all files together, caching compiler passes etc.). Hopefully with C++17, we will get some decent module system with symbol table imports rather than textual inclusion.

For C, the only use for precompiled headers if you have a very large project (Linux kernel maybe) with a lot of stable headers and a few frequently changed source files (kernel drivers?). Pre-compiling the headers might then save some time as well. For a C chess program, there is very little to be gained.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Strange bug - GCC does not detect existing member of boa

Post by bob »

Rein Halbersma wrote:
bob wrote:
Rein Halbersma wrote:
bob wrote:was going to suggest a couple of things to try, but it seems you have already fixed the problem...

I've not seen any version of gcc I use create any "pre-compiled headers" however...
https://gcc.gnu.org/onlinedocs/gcc/Prec ... aders.html

It is primarily used in C++ to decrease compilation times of the Standard Library headers (which are templates)
Notice my "gcc" and not "g++". I'm not a big c++ fan myself.
I know you are a C guy. That's why you haven't seen precompiled headers before, because the C standard library is already precompiled. :-)

For C++, there is also some precompiled stuff (iostreams and the rest of the runtime system), but the algorithms/containers stuff are templates and defined in headers. Same for most of Boost. E.g. for Visual C++, there is this stdafx.h header that contains all C++ standard library headers in precompiled form to save people from recompiling them over and over. C++ people have gone to great lengths to reduce compile times (concatenating all files together, caching compiler passes etc.). Hopefully with C++17, we will get some decent module system with symbol table imports rather than textual inclusion.

For C, the only use for precompiled headers if you have a very large project (Linux kernel maybe) with a lot of stable headers and a few frequently changed source files (kernel drivers?). Pre-compiling the headers might then save some time as well. For a C chess program, there is very little to be gained.
But the "headers" are not pre-compiled. They are plain text just like my own .h header files.
Rein Halbersma
Posts: 741
Joined: Tue May 22, 2007 11:13 am

Re: Strange bug - GCC does not detect existing member of boa

Post by Rein Halbersma »

bob wrote: But the "headers" are not pre-compiled. They are plain text just like my own .h header files.
No. Just recall how the preprocessor / compiler / linker work.

Suppose you have a header Deep.h that recursively includes many other headers, some of them multiple times. Each time the preprocessor sees an #include it has to do full textual inclusion. Include guards save you from including the same header multiple times within a single source file. But across source files, the preprocessor starts with a clean slate, has forgotten about all the include guards, and will have to do the whole textual inclusion game again. If you have deeply nested header inclusion and many source files including such a complicated header Deep.h, compile times will explode.

The way precompiled headers work is as follows:
- First, you designate Deep.h as the precompiled header. This should include all the stable headers that will not change during development.
- Second, you compile Deep.h with your regular compiler options. This will generate a Deep.pch (for Visual C++, and you need to add the /Yc flag) or Deep.gch (for gcc/g++). The Deep.pch is the file that results after the preprocessor has done all the recursive header inclusion and macro expansion, and after the compiler has generated the relevant code for structs and inline functions. It is not a plain text header.
- Third, you compile all your source files with the same compiler options that you used to create the precompiled header. Whenever the compiler now sees a Deep.h inclusion, it will skip textual inclusion, and instead restore the compiler state to that of Deep.gch, and continue compiling the rest of the source file.

So precompiled headers really are, well, precompiled. :-) BTW, this is not exactly new stuff, it was added to gcc 3.4 which was released over a decade ago.
User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: Strange bug - GCC does not detect existing member of boa

Post by lucasart »

Compilation time is a C++ problem. Only people who use C++ with STL/Boost and the likes have compilation time problems.

C compiles much faster, and its standard libraries are much lighter (ie. a lot less to compile).

There are other solutions than PCH:
* single source file including the other source files: ugly, but radical and effective. I think that's what Crafty does.
* Including less stuff. Putting includes in source instead of headers, when possible, goes a long way.

But yes, as a last resort, using PCH can be a good idea. You reach that last resort a lot quicker in C++ than in C, obviously…
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
Rein Halbersma
Posts: 741
Joined: Tue May 22, 2007 11:13 am

Re: Strange bug - GCC does not detect existing member of boa

Post by Rein Halbersma »

lucasart wrote:
There are other solutions than PCH:
* single source file including the other source files: ugly, but radical and effective. I think that's what Crafty does.
This is sometimes called "unity builds", and with e.g. CMake it can be supported automatically so that you can still develop using separate files.

There are also ccache (similar to precompiled headers, will cache compiler state) and distcc (increased parallelism) which are reported to reduce build times. YMMV.

BTW, you are absolutely right that with C, compile times are not an issue (for any projects smaller than the Linux kernel), so that makes Matthew's bug rather silly: he shouldn't have used precompiled headers in the first place, and if he did, he should use a proper make system to track changed dependencies.