After reading all answers, as well as compiler documentation, I decided I would follow the following standard.
For all files, be them project headers or external headers, always use the pattern:
#include <namespace/header.hpp>
The namespace being at least one directory deep, to avoid collision.
Of course, this means that the project directory where the project headers are should be added as "default include header" to the makefile, too.
The reason for this choice is that I found the following information:
1. The include "" pattern is compiler-dependent
I'll give the answers below
1.a Visual C++:
Source:
#include "MyFile.hpp"
The preprocessor searches for include files in the following order:
- In the same directory as the file that contains the #include statement.
- In the directories of any previously opened include files in the reverse order in which they were opened. The search starts from the directory of the include file that was opened last and continues through the directory of the include file that was opened first.
- Along the path specified by each /I compiler option.
- Along the paths specified by the INCLUDE environment variable.
#include <MyFile.hpp>
The preprocessor searches for include files in the following order:
- Along the path specified by each /I compiler option.
- When compiling from the command line, along the paths that are specified by the INCLUDE environment variable.
1.b g++
Source:
#include "MyFile.hpp"
This variant is used for header files of your own program. The preprocessor searches for include files in the following order:
- In the same directory as the file that contains the #include statement.
- Along the path specified by each -iquote compiler option.
- in the quote directories
- As for the #include
#include <MyFile.hpp>
This variant is used for system header files. The preprocessor searches for include files in the following order:
- Along the path specified by each -I compiler option.
- Inside the system directories.
1.c Conclusion
The pattern "" could lead to subtle compilation error across compilers, and as I currently work both on Windows Visual C++, Linux g++, and Solaris CC, this is not acceptable.
Anyway, the advantage of "" described features are far from interesting anyway, so...
2. Use the {namespace}/header.hpp pattern
I saw at work (i.e. this is not theory, this is real-life, painful professional experience) two headers with the same name, one in the local project directory, and the other in the global include.
As we were using the "" pattern, and that file was included both in local headers and global headers, there was no way to understand what was really going on, when strange errors appeared.
Using the directory in the include would have saved us time because the user would have had to either write:
#include <MyLocalProject/Header.hpp>
or
#include <GlobalInclude/Header.hpp>
You'll note that while
#include "Header.hpp"
would have compiled successfully, thus, still hiding the problem, whereas
#include <Header.hpp>
would not have compiled in normal circonstances.
Thus, sticking to the <> notation would have made mandatory for the developer the prefixing of the include with the right directory, another reason to prefer <> to "".
3. Conclusion
Using both the <> notation and namespaced notation together removes from the pre-compiler the possibility to guess for files, instead searching only the default include directories.
Of course, the standard libraries are still included as usual, that is:
#include <cstdlib>
#include <vector>