Archived

This topic is now archived and is closed to further replies.

FatalXC

Precompiled Headers

Recommended Posts

Hi, Could someone explain how/why these are useful, and what sort of things to put in stdafx.h? How do you add a PCH to a current project? Thanks, Richard

Share this post


Link to post
Share on other sites
The main benefit of using PCH files is to reduce compilation time. In large projects (hundereds of files), PCH files can cut 30% off of build times.

However, in my experience they can not always be trusted. Many of the nastiest and most ellusive bugs that I''ve come across have been caused by PCH files not being updated correctly.

Adding PCH files to existing projects is as simple as including the header files, and changing the project properties to use pre-compiled headers.

stdafx.h should only include files that you use in every file (or almost every file), maybe for example.

Share this post


Link to post
Share on other sites
In my project though, there are very few files that are always included, in many not even windows.h is included, so are PCHs going to be of no use in this situation?

Extra causes of bugs sounds raher unappealing.

Thanks,

Richard

Share this post


Link to post
Share on other sites
the only benefit is compilation time (and disk space consumption

I''d recommend only putting standard includes in the pch to avoid the mentioned bugs and to avoid rebuilding it as you change your headers. And then only use it if you are using big fat headers like windows.h



~~~
Cheers!
Brett Porter
PortaLib3D : A portable 3D game/demo libary for OpenGL
Community Service Announcement: Read How to ask questions the smart way before posting!

Share this post


Link to post
Share on other sites