Jump to content
  • Advertisement
Sign in to follow this  
orcfan32

.h and .hpp

This topic is 4838 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there a difference using a .h file or .hpp file with C++? I've ALWAYS use .h files, but I didn't know there was .hpp. Can anyone shed some light on this? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Mostly it's personal preference, though some C++ projects like boost mandate a .hpp extension. The preprocessor will expand anything no matter what its extension is.

Share this post


Link to post
Share on other sites
No, there is no actual difference, you could name the files .whatever and they'll still work.

Some people like to use .c/.h for C and .cpp/.hpp or .cc/.hh for C++. But I'd venture to guess that about 90% of the people out there are using .cpp/.h. (There are also some crazies (j/k) who use .C/.H for C++ but since on windows filenames are case insensitive this isn't the best scheme but it does show up in some older C++ sites I've read.)

(Note: the compiler does attempt to autodetect if a file is C/C++ by the name of the .c/.cpp/.cc/.C file, so it matters to an extent)

Share this post


Link to post
Share on other sites
Some people use .hpp to indicate a .h file with no corresponding .cpp file - e.g. when it's all inline or template code.

Share this post


Link to post
Share on other sites
Also if you ever have a project that mixes C and C++ files (God forbid), you might organize your code to have both a .h and .hpp file for each .cpp file. The .hpp file would contain all the usual C++ stuff, and the .h file would contain wrappers and stuff that gives your C files a way to access the functionality in the C++ code.

Share this post


Link to post
Share on other sites
A convention I have seen used is to use .h for C headers and C++ headers which are compatible with C (e.g. through the use of the __cplusplus macro), and .hpp for pure C++ headers.

Share this post


Link to post
Share on other sites
Quote:
Original post by Fruny
A convention I have seen used is to use .h for C headers and C++ headers which are compatible with C (e.g. through the use of the __cplusplus macro), and .hpp for pure C++ headers.


That's my usual convention to.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!