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

Discussion about everything. New games, 3d math, development tips...

Which extension do you use for headers?

.h
24
83%
.hpp
5
17%
 
Total votes: 29

MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

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

Post 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.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post 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.
Image Image Image
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

I'm using .h as well. not really sure what's the difference though.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post 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.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
twilight17
Posts: 362
Joined: Sun Dec 16, 2007 9:25 pm

Post 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)
Post this userbar I made on other websites to show your support for Irrlicht!
Image
http://img147.imageshack.us/img147/1261 ... wernq4.png
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post 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.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post 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..
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post 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++
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

i use .h if i creating the name of file
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post 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?
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

In a project, you're not always the one creating a file...
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post 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.
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Post 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.
twilight17
Posts: 362
Joined: Sun Dec 16, 2007 9:25 pm

Post 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
Post this userbar I made on other websites to show your support for Irrlicht!
Image
http://img147.imageshack.us/img147/1261 ... wernq4.png
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Yeah I've moved to .hpp too.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Post Reply