Can I split a long #include directive into two lines?

I do not like the idea of this, I just wanted to mention this possibility. The best is to go the way Daniel Fischer mentioned. This solution is a bit quirky and will not work under all circumstances but this compiled here:

#define PATH(FILE) </path/to/FILE>
#include PATH(file.h)

And just to name some of the obvious limitations:

  • the search path of these includes is not "local"
  • FILE must not contain "," (rather uncommon)
  • the PATH define can still exceed 80 characters

Feel free to add to this list.

Edit
Just for better readability I will post the solution from Jonathans comment below in the style of my example:

#define STRINGIFY(x) #x 
#define PATH(FILE) STRINGIFY(/path/to/FILE) 
#include PATH(foo.h)

This version mitigates the "locality problem" of the #include <> version, as it maps to #include ""


This compiles for me (I'm basing it off of how I recall Boost.PP working):

#define a() <vec\
tor>

#include a()

int main() {
  std::vector<int> x;
}

Just change <vector> to your full path - I don't think you can concatenate strings the way you need to in #include.


Use another header file with a short name to store header files with long names. So all headers that exceed you 80 character minimum is not in you nicely formatted code.

//short_name.h
#include "really_really_long_include_name.h"

//code
#include "short_name.h"