Pregunta

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:

  • Does anything bad happen if I include a file again that's already included in the precompiled header (I don't see why it would, but I've seen things about headers having to be included "in the same order", and not really understood what they were on about)?

  • Does it affect Intellisense (unusably slow with a fairly small project)? I'd be happy to give up some portability for better Intellisense since I currently have no desire to switch platforms.

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top