Header File Extension .h Or .hpp - C++ Forum
cplusplus.com
Return 0 (1282) I came across a few postings on another forum recently that debated which extension is correct and standard. From what I understand a .h header file is a C/C++ file while a .hpp is supposed to be a pure C++ file. I read that the Boost libraries (which I have yet to jump into) use .hpp extensions which is the future of the C++ spec. Is there any dominate preference out there or standard you see in place today? Advantages, disadvantages? I currently use .h. Thanks, Return 0;
helios (17607) The thing is, headers (any .h, .hpp, or any other extension I can't remember right now) are not compiled. They are only included by .cpps, so it doesn't really matter what extension they have, as long as the compiler knows it's not supposed to compile it.
Zaita (2770) .h is inherited from C. Typically, C applications use .h and .c (or .cc) C++ use .hpp and .cpp (pp = plus plus). It comes down to where you work/study and the preference they have to naming conventions. You'll notice even compilers are moving away from the .h for C++ (e.g it's now #include <iostream> not <iostream.h> And your right. Boost uses .hpp, but that's part of their convention. Last edited on
seymore15074 (449) Where I work, .h and .c are C files and .H and .C are C++.
helios (17607) And the compiler doesn't complain?
Bazzy (6281) I don't think that a compiler cares much about the file extension, it just compiles what you tell it to be compiled
helios (17607) Not really. GCC, for instance, ignores all headers even if you explicitly tell it to compile them.
seymore15074 (449) The valid extensions (supported by GNU) for C++ source files are .cc, .cpp, .cxx, or .C. The extension of the header file doesn't matter because it is just inserted into the source file by the preprocessor.
efexor (14) If you're using C++ it's better practice to use .hpp because .h is from C and so is .c, just like you use .cpp in C++ you should use .hpp in C++, Won't make a difference though.
closed account (42hU7k9E) Is iostream.h different than iostream? Why so?
Bazzy (6281) iostream without .h is the new version, the extension was removed to distinguish the two versions.
efexor (14) Most compilers that are up to standard don't the .h anymore, they ignore all headers. Last edited on
kbw (9488) There are times you want to distinguish between C and C++ headers. If you are using just one language, it doesn't really matter what you call your header files. But if you mix the languages in a library or application, it becomes important to seperate them. You can probably reply on __cplusplus being defined, and make up macros that wrap ' extern "C" ' and such C++ specific content, but the languages have subtle differences when confronted with common code (the size of enums, treatment of const variables for example). Back in the old CFront days, there was a .C and .H convention for C++ source and header files to avoid conflict with .c and .h for C. However, MS-DOS used a case-insensitive file system and so used .cpp and .hpp instead. Visual Studio's parser still recongnises .hpp and .inl as C++ files, so it's not a completely forgotten form. I think, if you're programming in just C++, feel free to use .h header files like everyone else. But if you're mixing languages, use .hpp for C++ and reserve .h for C. I also think it was a mistake to start using .h for C++ programs. Topic archived. No new replies allowed. Home page | Privacy policy© cplusplus.com, 2000-2025 - All rights reserved - v3.3.3Spotted an error? contact us
- TUTORIALS
- REFERENCE
- ARTICLES
- FORUM
C++
- Tutorials
- Reference
- Articles
- Forum
Forum
- Beginners
- Windows Programming
- UNIX/Linux Programming
- General C++ Programming
- Lounge
- Jobs
- Forum
- Beginners
- Header File extension .h or .hpp
Header File extension .h or .hpp
Từ khóa » .h .cpp .hpp
-
H Or *.hpp For Your Class Definitions - C++ - Stack Overflow
-
Why .h Is More Widely Used Than .hpp For C++ Header Files - Reddit
-
Thoughts On Header File Extensions: .h Vs .hpp - Embedded Artistry
-
HPP – The C++ Header File - Online Converter
-
HPP File Extension - What Is .hpp And How To Open? - ReviverSoft
-
Header Files (C++) - Microsoft Docs
-
Why Don't C++ Standard Headers' Names End With '.h' Or '.hpp'? - Quora
-
C++ Header File (*.h, *.hpp) - RAD Studio - Embarcadero DocWiki
-
What Is The Difference Between .h And .HPP Files? - AnswersToAll
-
C++ – .c Vs .cc Vs. .cpp Vs .hpp Vs .h Vs .cxx - ITecNote
-
[DEBT] Rename .h|.hpp|.cuh|.cu|.cpp Files Properly In Our Cuml C++ ...
-
Interface (.hpp) Versus Implementation (.cpp) Files (and Why They Exist)
-
Qt Why Use .h And .cpp Rather Than .hpp? - Qt Forum