Quantcast
Viewing all articles
Browse latest Browse all 22113

C++ Pre-compiled Headers: Two generated .gch are never identical for the same source file

I am trying to understand why pre-compiled header objects for a system header file are never the same between two compiler calls if the source file didn't change.

I can show this behavior with this very simple test:

$ cat pch.hpp
#include <string.h>

$ g++ pch.hpp -o pch1.hpp.gch && g++ pch.hpp -o pch2.hpp.gch
$ cksum pch1.hpp.gch pch2.hpp.gch
285552444 3408816 pch1.hpp.gch
612212458 3408816 pch2.hpp.gch

I could replicate this in Windows 7 (GCC 5.3.0 with MSYS2), Mac OS X (GCC 6.1.0 from Homebrew) and Arch Linux (GCC 6.1.1).

Looking at the dependencies, I couldn't find any predefined macro that could change the output between two consecutive compilations.

Comparing the generated files, some sequences of bytes are out of order (in the image, the string "pch.hpp" appears later in the file to the left) and some single bytes are different, even though the file sizes are the same.

Image may be NSFW.
Clik here to view.
Hexdump comparison

So does gcc really does not guarantee that the same PCH is generated each time or am I missing something?


Viewing all articles
Browse latest Browse all 22113

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>