SF.1: Use .hpp instead of .h for header files
May I suggested that .hpp be the proposed standard extensions for C++ header file instead of .h? Let .h be for header that compile with the C programming langage and .hpp be headers that compile with C++.
I'm of the opinion that .hpp is a good choice since is follows the standard form of source file (.cpp) and is also widely used (ie: Boost)
Many projects and development environments have mixture of "C" (e.g. system headers) and "C++". Many projects have legitimate reasons to distinguish the header files by extensions. Furthermore, there are many other well-established extensions, such as .hxx or .H. These choices should be left to individual projects.
Many projects and development environments have mixture of "C" (e.g. system headers) and "C++".
I recognize that many projects mix C and C++ and use .h files to allow the C++ compiler to use C-style function/structs/etc. However, I cannot think of a situation were we would want the C compiler to attempt to compile C++ code.
Furthermore, there are many other well-established extensions, such as .hxx or .H. These choices should be left to individual projects.
The core guideline does suggest using .cpp as the extension for source file even though it is not the only one used (.c++, .cxx, .cc, etc...). Furthermore, the core guideline does suggest .h as opposed to a C++ specific extension.
Beyond legacy, are there any reason to have the same extension being used by two difference programming language?
I agree with jfbilodeau. If the guidelines are going to recommend .cpp (and I’m not sure they should), then they should recommend .hpp for headers that are not meant to be included in C files. While .h should be recommended for files that are C and C++ compatible.
Or drop the .cpp recommendation and be silent on the matter.
@fisherro Ha, that is a left over and will be cleaned. Thanks!
If I may suggest, it might make more sense to move SF.1 to NL (Naming and Layout). I seems more appropriate.
Note that SF.1 does not actually mandate using ".cpp" and ".h". It already contains this note (emphasis added):
The specific names
.hand.cppare not required (but recommended) and other names are in widespread use. Examples are.hhand.cxx. Use such names equivalently.
Having said that, perhaps the title of the rule should be improved to avoid giving this misimpression...
Note that SF.1 does not actually mandate using ".cpp" and ".h".
The Guideline does not mandate, but suggests. Is there any good reason to suggest that C++ headers use the C extension (.h) as opposed to its own extension (.hpp)? Support for legacy code base doesn't sound like a good reason to me.
I recognized that from a technical perspective, the file extension has no bearing on the code itself but I feel that it would make it easier to differentiate between C and C++ code base. How many .h files are incorrectly tagged as C files on site such as GitHub and Tiobe?
...also, how many of us are sick of explaining that C and C++ are not the same language? ;)
We will clarify this paragraph.
-------- Original message -------- From: Jean-François Bilodeau [email protected] Date: 12/11/2015 3:27 PM (GMT-08:00) To: isocpp/CppCoreGuidelines [email protected] Cc: Gabriel Dos Reis [email protected] Subject: Re: [CppCoreGuidelines] SF.1: Use .hpp instead of .h for header files (#442)
Note that SF.1 does not actually mandate using ".cpp" and ".h".
The Guideline does not mandate, but suggests. Is there any good reason to suggest that C++ headers use the C extension (.h) as opposed to its own extension (.hpp)? Support for legacy code base doesn't sound like a good reason to me.
I recognized that from a technical perspective, the file extension has no bearing on the code itself but I feel that it would make it easier to differentiate between C and C++ code base. How many .h files are incorrectly tagged as C files on site such as GitHub and Tiobe?
...also, how many of us as sick of explaining that C and C++ are not the same language ;)
Reply to this email directly or view it on GitHubhttps://github.com/isocpp/CppCoreGuidelines/issues/442#issuecomment-164076560.
Sorry to resurrect the issue, but why is .h the recommended extension for interface file?
The CCG reason states 'convention', but the STL doesn't use it, neither does Boost and the extension already belongs to another programming language.
Clarified, thanks!