Skip to content

Fix convention for use of #include

I want to enforce that the form #include "path/to/header.h" is used only when path/to/header.h is a path relative to the source file being processed.

Rationale

According to the cppreference page, there is no difference between

#include <some_header.h>

and

#include "some_header.h"

except for a cryptic mention that the first is for headers and the second for sources, but it works for headers too.

In the notes it is explained that typical implementations (i.e. it is implementation specific but everybody does the same) search for the file to include in the same path as the source file being processed and if not found it falls back to the same logic used for the first form (i.e. an implementation defined search path).

This can be rephrased saying that when you use #include "some_header.h" you are signalling the compiler that you mean a path relative to the current source, while the form #include <some_header.h> means you do not want to consider a path relative to the current source (of course, you can invalidate this argument by adding -Ipath/to/source/dir before other headers directories in the compiler command invocation).

Edited by Marco Clemencic
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information