What's the difference between C header files (.h) and C++ header files (.hpp)?
I noticed that the boost library uses header files of (.hpp
).
.h
header files.
Could there be any special instances which warrant use of .hpp
instead of .h
?
Thanks
Just convention, nothing special. You can use any extension on include files, actually.
.hpp, .H, etc. is a loose convention for C++ header files, .tcc is a loose convention for C++ template implementation, .h is pretty strong convention for c files.
Boost uses hpp extension, QT uses .h extension, STL do not have extension. I am sure there are libraries which use .H but have not seen any.
Indeed, Otavio is correct.
I use hpp / h to differentiate between the two languages when building mixed-language products. For example, a class definition might go in a .hpp (implementation in .cpp), whereas a .h file would define only functions supported by C. To do this separation it is important to know the difference between the languages - to this end I pass *.c through gcc and *.cpp through g++.
The purpose of #include "filename"
preprocessor directive is to replace the #include
line with contents of filename
.
So infact any name for the file would do, but as it happens to be the convention the include files are ".h" or ".hpp", One advantage being the syntax highlighting in editor of your choice(vim in my case).
I hear it is also somewhat common for UNIX and Linux programmers to use .hh and .cc as opposed to .cpp and .h. Personally I like to name my header files .hh because it helps emacs distinguish between C and C++ syntax highlighting. I also use the .cc extension because it looks good together with .hh, and it's shorter than .cpp. And I usually do my coding in and for Linux environments.
you are just telling the compiler to include the given file in your code during compilation. so it doesnt matter what extension the file has. But preferably it should be text file.
精彩评论