user673679
user673679

Reputation: 1366

Precompiled headers, re-including files and Intellisense

I have a precompiled header that contains includes for various 3rd party libraries, e.g.:

#ifndef PRECOMPILED_H
#define PRECOMPILED_H

#include "booststuff.h"
#include "luastuff.h"

#endif

Where booststuff.h and luastuff.h are header files in my project that just include various boost / lua related things and set up some typedefs / usings / namespace aliases.

I set up the precompiled header in the usual way inside visual studio (2012), and use the force include option to include it in every cpp file.

In the cpp files, I've also been fairly careful to #include "booststuff.h" where I actually use it as well (I sometimes disable precompiled headers to test this). However, I've been wondering lately whether that's a good idea. So:

Upvotes: 2

Views: 991

Answers (1)

Mark Ransom
Mark Ransom

Reputation: 308402

If each include file has #pragma once in it, the compiler will completely skip reading the file on the second and subsequent attempts to include it. It isn't stated explicitly but I assume the precompiled header tracks this information as well.

Upvotes: 2

Related Questions