Strange bug - GCC does not detect existing member of board

Discussion of chess software programming and technical issues.

Moderator: Ras

ZirconiumX
Posts: 1362
Joined: Sun Jul 17, 2011 11:14 am
Full name: Hannah Ravensloft

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

Post by ZirconiumX »

Rein Halbersma wrote:
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.
I didn't use precompiled headers intentionally.

I think it could have gotten caught in a "GCC compile everything" command, which would explain it. I've removed all of them now.

Matthew:out
tu ne cede malis, sed contra audentior ito
Rein Halbersma
Posts: 771
Joined: Tue May 22, 2007 11:13 am

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

Post by Rein Halbersma »

ZirconiumX wrote:
I didn't use precompiled headers intentionally.

I think it could have gotten caught in a "GCC compile everything" command, which would explain it. I've removed all of them now.

Matthew:out
ah, yes, if you accidently compile a header file, you will get a .gch. At least on Windows, you also need to add the /Yc and /Yu flags, so there is less chance for such subtle errors.
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

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

Post by mcostalba »

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.
Another pro tip: Don't use the word 'bug' unless it refers to your code.

This will help you more than what you think.
Rein Halbersma
Posts: 771
Joined: Tue May 22, 2007 11:13 am

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

Post by Rein Halbersma »

mcostalba wrote: Another pro tip: Don't use the word 'bug' unless it refers to your code.

This will help you more than what you think.
I didn't mean "bug" in any negative way towards Matthew. Thanks for pointing out it could be interpreted that way.
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: 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.
I understand all of that. I was talking specifically about normal C header files where pre-compiling would not be beneficial in the least.