CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15

Thread: .hpp and .h

  1. #1
    Join Date
    Apr 2004
    Location
    In the back seat of New Horizons.
    Posts
    1,238

    .hpp and .h

    Is there a difference between the .h and .hpp files when I use them in C++? I realize that the latter is the header file specifically for C++, but will it give me any benefits if I use THAT particular file? Thanks in advance .
    Here are the rules, you must obey them or the gender bender will get you.

    And if you ever think of posting without code-tags, the evil monkey will come after you.

  2. #2
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656
    No, there isn't. You can call your includes whatever you like.
    (Unlike .c and .cpp files, where different compiler options might be used)
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  3. #3
    Join Date
    Apr 2004
    Location
    In the back seat of New Horizons.
    Posts
    1,238
    Quote Originally Posted by VladimirF
    No, there isn't. You can call your includes whatever you like.
    (Unlike .c and .cpp files, where different compiler options might be used)
    This ofcourse makes me wonder why someone would actually create .hpp files?
    Here are the rules, you must obey them or the gender bender will get you.

    And if you ever think of posting without code-tags, the evil monkey will come after you.

  4. #4
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Quote Originally Posted by YourSurrogateGod
    This ofcourse makes me wonder why someone would actually create .hpp files?
    Well...it's a matter of personal style...I basically always use the '.hpp' extension simply to indicate that the content of this header file cannot be used with C...

  5. #5
    Join Date
    Apr 2004
    Location
    In the back seat of New Horizons.
    Posts
    1,238
    Quote Originally Posted by Andreas Masur
    Well...it's a matter of personal style...I basically always use the '.hpp' extension simply to indicate that the content of this header file cannot be used with C...
    Good point.
    Here are the rules, you must obey them or the gender bender will get you.

    And if you ever think of posting without code-tags, the evil monkey will come after you.

  6. #6
    Join Date
    Oct 2000
    Location
    London, England
    Posts
    4,773
    I use the following:

    .hpp: file is totally inlined.

    .hxx: header file, there is a corresponding .cxx file. Header is part of the implementation and not the interface

    .h: header file is an entry point, i.e. it forms part of the interface.

  7. #7
    Join Date
    Apr 2004
    Location
    In the back seat of New Horizons.
    Posts
    1,238
    Quote Originally Posted by NMTop40
    I use the following:

    .hpp: file is totally inlined.

    .hxx: header file, there is a corresponding .cxx file. Header is part of the implementation and not the interface

    .h: header file is an entry point, i.e. it forms part of the interface.
    What do you mean when you say 'inlined'? How can an entire file be 'inlined'? I am not following you.
    Here are the rules, you must obey them or the gender bender will get you.

    And if you ever think of posting without code-tags, the evil monkey will come after you.

  8. #8
    Join Date
    Oct 2000
    Location
    London, England
    Posts
    4,773
    It means all the implementation is in the header file and you do not need to link it in with another library.

    Doing this can be useful:

    - for general utilities.

    - When the implementation does not bring in any new dependencies, i.e. it does not increase the dependencies that you have already.

    - For writing an implementation of a base class where this implementation is internal to your module and will be included only by other files within your module.

    I have considered using a 4th possible extension, for example .hh, so we can split up headers further (inlined, implemenatation and inlined, entry point).

  9. #9
    Join Date
    Apr 2004
    Location
    In the back seat of New Horizons.
    Posts
    1,238
    Quote Originally Posted by NMTop40
    It means all the implementation is in the header file and you do not need to link it in with another library.

    Doing this can be useful:

    - for general utilities.

    - When the implementation does not bring in any new dependencies, i.e. it does not increase the dependencies that you have already.

    - For writing an implementation of a base class where this implementation is internal to your module and will be included only by other files within your module.

    I have considered using a 4th possible extension, for example .hh, so we can split up headers further (inlined, implemenatation and inlined, entry point).
    Hmm... Never thought that it would be possible to just add on countless letters after .h in order to use it in a .cpp file. Thanks.
    Here are the rules, you must obey them or the gender bender will get you.

    And if you ever think of posting without code-tags, the evil monkey will come after you.

  10. #10
    Join Date
    Mar 2004
    Location
    Israel
    Posts
    638
    I'm curious how do you treat your own namespaces.
    do you keep it as one unit?
    **** **** **** **** **/**

  11. #11
    Join Date
    Apr 2004
    Location
    In the back seat of New Horizons.
    Posts
    1,238
    Quote Originally Posted by Guysl
    I'm curious how do you treat your own namespaces.
    do you keep it as one unit?
    I'm not their biggest fan really, unless it is for some very specific example, I see them on a day-to-day basis as something pointless really. Hence I don't have a uniform way of dealing with them. If I ever had a project that would require me to use namespaces often, then I would come up with a structured manner in which to deal with.
    Here are the rules, you must obey them or the gender bender will get you.

    And if you ever think of posting without code-tags, the evil monkey will come after you.

  12. #12
    Join Date
    Oct 2000
    Location
    London, England
    Posts
    4,773
    You might not need multiple namespace but it would be a good idea to have 2 layers at least.

    company_name::group_name

    (or use acronyms).

    That way, if your company ever merges code in from another company or another group within the company, you do not need to worry if the others have used the same names as yourself.

  13. #13
    Join Date
    Apr 2004
    Location
    In the back seat of New Horizons.
    Posts
    1,238
    Quote Originally Posted by NMTop40
    You might not need multiple namespace but it would be a good idea to have 2 layers at least.

    company_name::group_name

    (or use acronyms).

    That way, if your company ever merges code in from another company or another group within the company, you do not need to worry if the others have used the same names as yourself.
    Good point. However, my personal dislike of namespaces comes from the fact that the program seems to be more chaotic. Usually I just use classes and inheritance in order build hierarchial tree, that way it's easier to trace functions and what they do. It gives a good level of control. Imo.

    I think that this will be something that I'll look into carefully when I come to writing more complex programs that are supposed to run over a network.
    Here are the rules, you must obey them or the gender bender will get you.

    And if you ever think of posting without code-tags, the evil monkey will come after you.

  14. #14
    Join Date
    Mar 2004
    Location
    Israel
    Posts
    638
    NMTop40,
    Well I didn't really ask about the need of namespaces.
    Say I have created a namespace that containes templates and non-templates elements. How would you structure your header files for such a namespace?
    **** **** **** **** **/**

  15. #15
    Join Date
    Oct 2000
    Location
    London, England
    Posts
    4,773
    It's not really a matter of structuring in namespaces and templates. Think of it as a module. A single unit that may include several classes.

    You use the module.

    You should not be forced to include any more than you need to know. But for me that will sometimes mean header files.

    Are the templates part of the interface or are they simply there to help with the implementation?

    And in case you are wondering why it can be a useful thing to do, have a look at boost and STL. With those, you generally only need to include the header files to use the classes. You do not need subsequently to link in any library. (You do with some of boost).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured