[ACCEPTED]-What's the difference between C header files (.h) and C++ header files (.hpp)?-c

Accepted answer
Score: 23

Just convention, nothing special. You can 1 use any extension on include files, actually.

Score: 6

.hpp, .H, etc. is a loose convention for 7 C++ header files, .tcc is a loose convention 6 for C++ template implementation, .h is pretty 5 strong convention for c files.

Boost uses 4 hpp extension, QT uses .h extension, STL 3 do not have extension. I am sure there 2 are libraries which use .H but have not 1 seen any.

Score: 2

Indeed, Otavio is correct.

I use hpp / h 9 to differentiate between the two languages 8 when building mixed-language products. For 7 example, a class definition might go in 6 a .hpp (implementation in .cpp), whereas 5 a .h file would define only functions supported 4 by C. To do this separation it is important 3 to know the difference between the languages 2 - to this end I pass *.c through gcc and 1 *.cpp through g++.

Score: 1

The purpose of #include "filename" preprocessor directive is 6 to replace the #include line with contents of filename.
So 5 infact any name for the file would do, but 4 as it happens to be the convention the include 3 files are ".h" or ".hpp", One advantage 2 being the syntax highlighting in editor 1 of your choice(vim in my case).

Score: 0

I hear it is also somewhat common for UNIX 9 and Linux programmers to use .hh and .cc 8 as opposed to .cpp and .h. Personally I 7 like to name my header files .hh because 6 it helps emacs distinguish between C and 5 C++ syntax highlighting. I also use the 4 .cc extension because it looks good together 3 with .hh, and it's shorter than .cpp. And 2 I usually do my coding in and for Linux 1 environments.

Score: 0

you are just telling the compiler to include 3 the given file in your code during compilation. so 2 it doesnt matter what extension the file 1 has. But preferably it should be text file.

More Related questions