|
|
| C++ header files: .h or .hpp |
|
Marco Radaelli
Member #3,028
December 2002
|
I'm wondering if there's any standard about it. In case there isn't, which is the most common between .h and .hpp extensions? I'll use g++ as compiler.
|
|
Vanneto
Member #8,643
May 2007
|
C: .h C++: .hpp. But you can name them whatever you want actually, .foo, .bar or .awesome_header if you like. -- |
|
HoHo
Member #4,534
April 2004
|
I use .h for both as I don't see a particularly good reason to make a difference between C and C++ headers (I code nearly 100% in C++). Good file managers can make difference without looking the extension __________ |
|
Johan Halmén
Member #1,550
September 2001
|
I never got it explained to me why f.i. the stl stuff uses no extensions. Like string or vector. Neither do I know what you call the opposite to a rhetoric question. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
kazzmir
Member #1,786
December 2001
|
Quote: I never got it explained to me why f.i. the stl stuff uses no extensions. Like string or vector. http://www.new-brunswick.net/workshop/c++/faq/coding-standards.html#faq-27.4 And for naming your own headers But basically some editors can figure out the type of the file based on the extension so .h, .hpp, or .hh are ok. I tend to use .h. |
|
Mark Oates
Member #1,146
March 2001
|
Is .inl just an allegro thing? Quote: Neither do I know what you call the opposite to a rhetoric question. Hmm.. never thought about it. I've just heard "That's not a rhetorical question". |
|
Tobias Dammers
Member #2,604
August 2002
|
Quote: Neither do I know what you call the opposite to a rhetoric question. Um, just 'question' I suppose. As for the original question: .h and .hpp are the most popular ones. Technically it doesn't matter what you use, because an #include is just a brute-force text replacement regardless of file type or language: the preprocessor doesn't know any actual C or C++, and consequently doesn't need to know what the language is. Theoretically, you could just as well use the preprocessor for any other language. The .c vs. .cpp/.cc difference DOES matter though, since the compiler uses the extension to determine the language. In practice, it is convenient to use something that your editor 'knows'; since highlighting rules are probably the same for C and C++, you can just use .h for both, unless you have a project that's partially C and partially C++ (like a library that works with C++ behind the scenes, but has a plain C API); in that case, using different extensions may avoid confusion. Whatever you do, using capital letters (.H and .C for C++ vs. .h and .c for plain C) is obviously not a good idea if you want your code to be remotely cross-platform. --- |
|
aj5555
Member #9,033
September 2007
|
.h ftw |
|
Marco Radaelli
Member #3,028
December 2002
|
I'm going with .hpp for consistency with .cpp
|
|
Thomas Fjellstrom
Member #476
June 2000
|
Quote: Is .inl just an allegro thing? I'm sure other projects use it, but the extension used for #include files doesn't matter one bit. GCC however cares what the source file extension is (and if you're compiling a compiled header, the source file is a header! go figure). -- |
|
|