Possible Duplicates:
*.h or *.hpp for your class definitions
Correct C++ code file extension? .cc vs .cpp
I used to think that it used to be that:
.h
files are header files for C and C++, and usually only contain declarations..c
files are C source code..cpp
files are C++ source code (which can also be C source code).then files like .hpp
, .cc
, and .cxx
came along, and I got totally confused... what's the difference(s) between those? When do you use the "new" ones?
This question is related to
c++
c
filenames
header-files
naming
I use ".hpp" for C++ headers and ".h" for C language headers. The ".hpp" reminds me that the file contains statements for the C++ language which are not valid for the C language, such as "class" declarations.
Those extensions aren't really new, they are old. :-)
When C++ was new, some people wanted to have a .c++ extension for the source files, but that didn't work on most file systems. So they tried something close to that, like .cxx, or .cpp instead.
Others thought about the language name, and "incrementing" .c to get .cc or even .C in some cases. Didn't catch on that much.
Some believed that if the source is .cpp, the headers ought to be .hpp to match. Moderately successful.
It really doesn't matter.
If you feed .c to a c++ compiler it will compile as cpp, .cc/.cxx is just an alternative to .cpp used by some compilers.
.hpp is an attempt to distinguish header files where there are significant c and c++ differences. A common usage is for the .hpp to have the necessary cpp wrappers or namespace and then include the .h in order to expose a c library to both c and c++.
Talking about .hpp extension, I find it useful when people are supposed to know that this header file contains C++ an not C, like using namespaces or template etc, by the moment they see the files, so they won't try to feed it to a C compiler! And I also like to name header files which contain not only declarations but implementations as well, as .hpp files. like header files including template classes. Although that's just my opinion and of course it's not supposed to be right! :)
Generally, .c and .h files are for C or C-compatible code, everything else is C++.
Many folks prefer to use a consistent pairing for C++ files: .cpp with .hpp, .cxx with .hxx, .cc with .hh, etc. My personal preference is for .cpp and .hpp.
Source: Stackoverflow.com