What is the difference between hpp and hxx?

for gcc they should be the same, right? which one of them is more popular, now I am preparing a project from scratch, and I would like to choose one of them.

thanks

+9
c ++
source share
5 answers

In C ++, the file extension does not actually matter. Using .h, .hpp, .hxx or any file extension is all by convention.

The standard library does not use the file extension for its header files. Many projects, including Boost, use .hpp. Many projects use .h. Just pick one and be consistent in your project.

+19
source share

The compiler does not distinguish between these two extensions, so it is technically not important which one you use. Personally, I use the .hxx extension for header files that are used only within the project, and .hpp for those that need to be released using the library / software.

+4
source share

I suggest that we reopen this discussion in light of the recent discovery that I made. Over the past 9 years, I have used the following naming convention for source files in my C and C ++ projects.

  • C = Direct source code C containing one or more related entry points
  • CPP = C ++ source code containing one or more related entry points
  • H = Declaration of functions, macros, structures, typedefs, etc.
  • INL = Inline (function bodies), which are the bodies of two or more functions, the main definition file of which is the C or CPP file in which they are included: #include

An example of these common function bodies, MyStringFunctionA, an ANSI implementation, is defined in MyStringFunctionA.cpp, and the implementation of MyStringFunctionW, Unicode (wide character), is defined in MyStringFunctionW.cpp. MyStringFunctionA.cpp and MyStringFunctionW.cpp contain prototypes that open and close brackets and headers, provided UNICODE for the wide-character version. The body of the function is defined in the INI file, which contains # built-in built-in function definition block.

Combined with the universal TCHAR mappings, this approach greatly simplifies support for the Unicode and ANSI versions that remain in active use.

This naming convention worked great with Visual Studio 6. However, when I started migrating my code base in Visual Studio 2013, I found that the change annoyed me. Although everything was compiled when one of my INL files was opened in the code editor, I will see dozens of Intellisense errors listed in the Errors window. I quoted the term “errors” because these are not true errors; they disappear when the INL file is closed, and the C and CPP files into which iNL is pulled are compiled without errors, links, and run correctly.

+2
source share

The header file extensions usually do not matter, but I know that in some cases the .cpp file extension may matter. Depending on your compiler, the front-end may choose to compile the source file as C or C ++.

This can make a difference, especially if you combine compilation with the link phase, as it can lead to linking different libraries (e.g. g ++ vs gcc), and therefore you can control the result in your file.

0
source share

The header file of the source code written in the C ++ programming language; may include data types, constants, variables, and other definitions; used to declare and store reusable code components. HXX files can be inserted into a C ++ program using the #include directive. For example, #include myHeader.hxx tells the C ++ compiler to include "myHeader.hxx" in the current program file.

0
source share

All Articles