Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » C++ header files: .h or .hpp

This thread is locked; no one can reply to it. rss feed Print
C++ header files: .h or .hpp
Marco Radaelli
Member #3,028
December 2002
avatar

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
avatar

C: .h C++: .hpp.

But you can name them whatever you want actually, .foo, .bar or .awesome_header if you like.

--
May you one day find Allah in your hearth and accept His Word as The Truth!

HoHo
Member #4,534
April 2004
avatar

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 :)

__________
In theory, there is no difference between theory and practice. But, in practice, there is - Jan L.A. van de Snepscheut
MMORPG's...Many Men Online Role Playing Girls - Radagar
"Is Java REALLY slower? Does STL really bloat your exes? Find out with your friendly host, HoHo, and his benchmarking machine!" - Jakub Wasilewski

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.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This thread is obviously about nothing so heres a bunny with a pancake on its head. -kazzmir

kazzmir
Member #1,786
December 2001
avatar

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
avatar

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
avatar

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.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

aj5555
Member #9,033
September 2007

.h ftw

Marco Radaelli
Member #3,028
December 2002
avatar

I'm going with .hpp for consistency with .cpp :)
Thank you :)

Thomas Fjellstrom
Member #476
June 2000
avatar

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).

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro SVN Snapshots] - [Allegro TODO] - [Web Hosting]
"God Bless Joe Pesci" -- George Carlin
"Goto is the buldozer of coding. Sometimes, the buldozer is just the right tool for the job. Not often, but sometimes." -- LordBob

Go to: