C++: Reason why using ".hh" as extension for C++ header files
You can name your headers as you wish, they can even have no extension at all.
This FAQ mentions header naming conventions.
I think it is mostly a social convention.
However, recent GCC compilers are able to compile a (single) header foo.hh
or foo.h
into something like foo.hh.gch
or foo.h.gch
which essentially contains a persistent memory heap image of the compiler (the cc1plus
program started by g++
) after it had parsed that header.
Notice that the C++11 standard library defines header files like e.g. <vector>
without any extension.
It's not for any specific reason, it's just a (developer- or project-specific) convention. As "file extension" is just part of name, it doesn't matter much, as source files are just plain text files. Furthermore, header files are just copy-pasted into file that included them (via #include
, so file extension mean even less for them.
Borland's libraries' headers had .hpp
extension. C++'s standard library headers have no extension at all. It's just a matter of convention and personal taste.
Some say, we are using ".cc" as extension for C++ files to differentiate from C files (which has an extension ".c"), likewise we are using using ".hh" as extension for C++ header files to differentiate from C header files (which has an extension ".h").
That is exactly the reason. It is just to differentiate CPP headers from C headers.
Some programmers and libraries, such as Boost, use .hpp
for CPP headers. My personal choice is this:
- example.c
- example.cpp
- example.h
- example.h++
Even if they all belong to a huge project, you can still figure out which one is which. No description is needed.