1

I was playing with cpplint and I got this warning:

Found C++ system header after other header. Should be: transpose_square.h, c system, c++ system, other.

The source is the Google Styleguide, that apparently says (said?)

1. associated .h/.hpp (if this is a .cpp file)
2. C system files
3. C++ system files
4. Other libraries' .h/.hpp files
5. Your project’s .h/.hpp files

Leaving aside 1., I honestly thought that the recommended order was exactly the opposite!

2. Your project’s .h/.hpp files
3. Other libraries' .h/.hpp files
4. C++ system files
5. C system files

So, basically the idea is to include the headers in the order of "increasing distance" from the current project, ending with the most basic libraries.

I don't remember where I took that from, but I remember the logic was to detect missing dependencies headers in related or in the same project.

I don't remember if there was more than just this.

For example, in this case, the order will be forgiving for text_processing_utilities.hpp to have a missing #include<string> even if it depends on it:

#include<string>
#include "text_processing_utilities.hpp"

My question is, is the Google Style guide for headers a good convention regarding the order of system headers? Is there a good reason for it?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
alfC
  • 14,261
  • 4
  • 67
  • 118
  • Found an answer here: https://stackoverflow.com/questions/2762568/c-c-include-header-file-order/14243688#14243688 – alfC Oct 12 '22 at 03:18
  • 1
    Who ever said the google style guide was good. I have never seen a good argument for it! Personally I use the order you suggest. My reasoning is that this way will expose missing headers that are required for that header file to stand alone. The way I express it is: Order headers from Most specific to Most general (relative to your project). C system files being the most generic functionality you can get that everybody else depends on. – Martin York Oct 12 '22 at 04:49
  • You're right, I thought that was stupid, after all, it's just a "style", do what you want as long as it is comfortable for you, and the others. – thedemons Oct 12 '22 at 06:10
  • In the help is stated that cpplint has other options, such as `build/include_alpha` which I see used as `filter=-build/include_order,+build/include_alpha,+build/include_subdir`. But it is not clear what they mean. – alfC Oct 12 '22 at 18:16

0 Answers0