C++ Headers Include Order

As working on my side project, one thing I have settled down is to have a consistent header file include order. My solution is very similar to what Google recommends in its C++ style guide.

Here is mine:

<<Current file’s header file>>

<<C library files>>

<<C++ library files>>

<<Other library files>>

<<header files under the same module as the current file>>

<<header files in other modules>>

<<header files in utility module>>

  • Every file path is specified to be relative to the project source directory.
  • Inside each section, files are ordered in alphabetic order.
  • For clarity, sections are separated by one empty line.

Here is a bogus code snippet for my ParserDriver.cpp

#include “Parser/ParserDriver.h”

#include <sys/types.h>

#include <fstream>

#include <iostream>

#include <sstream>

#include <antlr3.h>

#include “Parser/SQLLexer.h”

#include “Parser/SQLParser.h”

#include “Parser/SQLSemanticAnalyzer.h”

#include “Expr/BinaryExpr.h”

#include “Expr/BooleanExpr.h”

#include “Expr/ColumnExpr.h”

#include “Expr/ConstantExpr.h”

#include “Storage/IStorage.h”

#include “Utils/Common.h”

#include “Utils/Debug.h”

#include “Utils/Status.h”

#include “Utils/Types.h”

So far, I am pretty happy with it and will stick with this order in my project.