开发者

what's the difference between hpp and hxx?

for gcc t开发者_高级运维hey should be the same, right? which one of them is more popular , i am now preparing a project from scratch and i would like to pick one among these 2.

thanks


In C++, the file extension doesn't actually matter. The use of .h, .hpp, .hxx, or no file extension are all by convention.

The standard library uses no 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.


The compiler doesn't distinguish between the two extensions, so technically it doesn't matter which one you use. Personally I use the .hxx extension for header files that are only used internally in the project, and .hpp for those that should be release with the library/software.


I propose that we re-open this discussion, in view of a recent discovery that I made. For the last 9 years, I have used the following naming convention for the source files in my C and C++ projects.

  • C = Straight C source code, 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) that are the bodies of two or more functions whose main definition file is a C or CPP file, into which they are incorporated by #include

An example of these common function bodies, MyStringFunctionA, the ANSI implementation, is defined in MyStringFunctionA.cpp, while MyStringFunctionW, the Unicode (wide character) implementation, is defined in MyStringFunctionW.cpp. MyStringFunctionA.cpp and MyStringFunctionW.cpp contain the prototype, opening and closing brackets, and headers, subject to UNICODE for the wide character version. The function body is defined in the INI file, which is #included inline, within the function definition block.

Combined with generic TCHAR mappings, this approach greatly simplifies maintaining Unicode and ANSI versions, both of which remain in active use.

This naming convention worked great with Visual Studio 6. However, when I began migrating my code base to Visual Studio 2013, I discovered an annoying change that was initially confusing. Although everything compiled cleanly, when one of my INL files was open in the code editor, I would see dozens of Intellisense "errors" listed in the Errors window. I quoted the term "errors" because they are not true errors; they vanish when the INL file is closed, and the C and CPP files into which the iNL is pulled compile without errors, link, and run correctly.


Header file extensions don't usually make a difference, but I know that in some cases the extension of the .cpp file can make a difference. Depending on your compiler the front-end may choose to compile the source file as either C or C++.

This can make a difference, especially if you are combining compilation with the link phase, as it can lead to different libraries being linked (e.g. g++ vs gcc) and so you can control the outcome in your makefile.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜