Page 1 of 2

Do you use .h or .hpp ending for header files?

Posted: Sun Feb 10, 2008 6:46 pm
by MasterGod
I'm interested why I don't see that extension, does .hpp so "bad" nobody uses it? The only places I've seen it is with my friend's library and FMOD Ex..
I'm really interested how many of you actually use it and if not why not? Is it just a habit? You just hate typing 2 more characters, what's the reason?

I'm using .h for my project just because I didn't knew of .hpp until few months before I met irrlicht which uses .h only so I stayed with it..
Unless I'll hear anything intimidating I think I'll changed'em all to .hpp..

P.S
I understood .h is for C and .hpp is for C++.. Am I wrong or is it just another standard.

Posted: Sun Feb 10, 2008 7:12 pm
by JP
I guess it's just something someone came up with to show that the header file belongs with a C++ file instead of a C file...

Personally i always use .h and i don't think i've actually ever seen .hpp in use.

Posted: Sun Feb 10, 2008 7:27 pm
by Virion
I'm using .h as well. not really sure what's the difference though.

Posted: Sun Feb 10, 2008 7:43 pm
by MasterGod
JP wrote:Personally i always use .h and i don't think i've actually ever seen .hpp in use.
As FMOD Ex has pure C implementation and C++ implementation there's fmod.h and fmod.hpp and that's the only place I've seen .hpp files too.

Posted: Sun Feb 10, 2008 7:46 pm
by twilight17
I use .h...

but it really doesn't matter

(Can't you use anything you want? Such as .lol, because you can then just include whatever.lol --although this would probably confuse a ton of people)

Posted: Sun Feb 10, 2008 8:14 pm
by rogerborg
Yes, #include "foo.lol" is perfectly valid, as is #include "foo".

I don't use .hpp but I actually do think that in theory if you use .cpp then you should also use .hpp (in as much as any file extension is a good thing).

That's because the verbatim nature of #include makes the distinction between "source" and "header" files in C/C++ a matter of convention. All C or C++ source is "source", and any individual C or C++ file (regardless of its extension) should be compilable on its own. It should not[1] rely on any "source" file to include anything else beforehand.

Very occasionally I do put together special build targets that build every "include" file in my projects individually, using an appropriate compiler switch to force compilation. This verifies that each "include" file includes everything necessary for it to compile, which makes them a lot more portable and saves some unnecessary over-including of things in "source" files.

So once you get used to viewing "header" files as just another source file, .hpp makes a lot of sense. It's really just a bad habit from C days that keeps me using .h and I may very well be tempted to script a find-and-replace on my projects on the back of this.

Or I may just eat some pie instead. It could go either way.

[1] In general, but I make an exception for #define switches that alter behaviour.

Posted: Sun Feb 10, 2008 9:49 pm
by MasterGod
I've changed all the headers in my project to .hpp now, I don't know why but I like .hpp more then the old .h..

Posted: Sun Feb 10, 2008 9:59 pm
by Dorth
I use .h most of the times, .hpp sometimes, but you should use .hpp when your header is part of a c++ obj and .h when it's part of a c obj. Of course, .h is shorter and since people see the .cpp associated, they get it's c++. Also, sometimes with libraries and dll, the header is proper c while the body is c++. But since only the .h is distributed, it's compatible c/c++

Posted: Mon Feb 11, 2008 12:30 pm
by greenya
i use .h if i creating the name of file

Posted: Mon Feb 11, 2008 2:28 pm
by MasterGod
greenya wrote:i use .h if i creating the name of file
I don't know how it is with other compilers but VC also generate .h not .hpp.
Well, you said "if", which compiler do you use then that generate .hpp files?

Posted: Mon Feb 11, 2008 3:07 pm
by Dorth
In a project, you're not always the one creating a file...

Posted: Mon Feb 11, 2008 4:35 pm
by greenya
MasterGod wrote:
greenya wrote:i use .h if i creating the name of file
I don't know how it is with other compilers but VC also generate .h not .hpp.
Well, you said "if", which compiler do you use then that generate .hpp files?
When i said "if i creating the name of file" -- i meant that if naming file by my self (not another member of the team (of project)).
And also: i do not use generating-features of IDE -- i always specify name with extension while creating new file.
p.s.: I'm using MS VS 2005 TS.
p.p.s.: If you talking about IDE while saying "which compiler do you use then that generate .hpp files?" -- i never met IDEs that generates .hpp extensions if you ask it to.

Posted: Sat Feb 16, 2008 9:21 pm
by randomMesh
From the Boost FAQ:

"Why do Boost headers have a .hpp suffix rather than .h or none at all?

File extensions communicate the "type" of the file, both to humans and to computer programs. The '.h' extension is used for C header files, and therefore communicates the wrong thing about C++ header files. Using no extension communicates nothing and forces inspection of file contents to determine type. Using '.hpp' unambiguously identifies it as C++ header file, and works well in actual practice."

I really like the extension '.lol', btw.

Posted: Sat Feb 16, 2008 9:28 pm
by twilight17
Yeah, .lol pwns :mrgreen:

Anyway, I'm going to use .hpp from now on.. It's easier to understand.. I think everyone should use it from now on. :D

Posted: Sat Feb 16, 2008 9:44 pm
by MasterGod
Yeah I've moved to .hpp too.