/Y3 where have you been all my life


I was just flicking through some of the entries over on Games from Within and I came across an entry on precompiled headers which is a good introduction of the pros and cons of using precompiled headers in a cross platform environment.

I wanted to comment on this posting but the comments seem to be turned off for it now so I'll comment here...

Noel covers the whys and why nots of precompiled headers a lot better than I did when I wrote about them a while ago, however he fails to mention the "one true way" of using precompiled headers on Microsoft compilers...

Using #pragma hdrstop and the /Yc or /Yu compiler flags allows you complete control of your precompiled header and it also allows you to build the sources without the precompiled header so that you can work around the downsides of using precompiled headers (accidental coupling and full rebuilds). I tend to create an extra build configuration for a debug build with no precompiled headers and use that when developing if I'm regularly changing header files. All of the other configurations use precompiled headers.

For a working example of how to use #pragma hdrstop, the compiler flags and an extra no precompiled header build configuration see the code that comes with the latest entry on Practical Testing.

Noel linked to Bruce Dawson's article on precompiled headers in Visual C++ and the best thing about this guide is that it starts off by showing you how to get Visual Studio to display build times automatically using the undocumented /y3 option. You need to pass this option to devenv.exe by adding it to the command that your Visual Studio 6 shortcut runs. There are similar, but more easilly accessible, methods for obtaining timings from later versions of Visual Studio. This option is great, as it makes it easy to see that doing precompiled headers the right way is well worth it! The code I'm working on at present takes 2.10 to build with no precompiled headers and 0.52 with precompiled headers turned on. That's enough of a win for me to not bother with tuning the files that are included in the precompiled file too much at this point but it will be SO much easier to do that tuning in future...

A google search for other undocumented VC6 switches didn't shed much light but it did take me to this page, which is a useful collection of hints and tips.

Leave a comment