Is an #include before #ifdef/#define Include-Guard okay?

avb picture avb · Jan 8, 2014 · Viewed 10.1k times · Source

I always placed my #include after the #ifdef/#define Include-Guard. Now the refactor mechanism of my IDE (Qt Creator) put it before the Include-Guard e.g.

#include "AnotherHeader.h"

#ifndef MYHEADER_H
#define MYHEADER_H

Can this cause any problems or can I leave it this way?

Answer

nvoigt picture nvoigt · Jan 8, 2014

If the header in question has include guards itself, you won't run into problems. Putting it inside the include guards may still speed up compilation. Something the compiler does not see takes less time to compile, even if it does not produce any errors.