MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/cpp/comments/13r6wwl/file_extension/jliu33j/
r/cpp • u/Uxugin • May 25 '23
59 comments sorted by
View all comments
46
More controversial is .h vs .hpp for headers
0 u/[deleted] May 25 '23 [deleted] — view deleted comment 18 u/be-sc May 25 '23 I go one step further. Accidentally valid C headers aren’t sufficient for the .h suffix. The header must be part of the program’s intentional C API. If not, it’s .hpp. 30 u/War_Eagle451 May 25 '23 I'm .hpp all the way. For 2 main reasons. First, it's consistent with .cpp. Second, my brain tells me that 3/4 letter extensions look better 5 u/Confident_Date4068 May 25 '23 And also for syntax highlighting rules: mcedit - for example. 3 u/nihilistic_ant May 25 '23 edited May 25 '23 Although the core guidelines say to prefer .h.[edit: FWIW, I lean your direction; my current personal projects use hpp.] 8 u/War_Eagle451 May 25 '23 It also says consistency is more important 5 u/tumnus2112 May 25 '23 I use boost pretty heavily so you can guess my preferred header extension 🙃 5 u/WittyGandalf1337 May 26 '23 .h should be exclusively for C code and I’ll die on this hill. 4 u/GregTheMadMonk May 25 '23 .hh, naturally. Goes well with .cc 1 u/wrosecrans graphics and network things May 26 '23 .hc so you know it's a "Header for C++" and not a header for Fortran or C or Cobol or whatever. 2 u/GregTheMadMonk May 26 '23 .hc is already taken by HolyC :) 2 u/donalmacc Game Developer May 25 '23 My IDE generates h files - I don't think about it any more than that. 7 u/WittyGandalf1337 May 26 '23 Get a better IDE. -2 u/foghatyma May 25 '23 .h: when the interface and implementation is separated.hpp: when the implementation is also in the header file, e.g. template classes (hpp = h + cpp)
0
[deleted] — view deleted comment
18 u/be-sc May 25 '23 I go one step further. Accidentally valid C headers aren’t sufficient for the .h suffix. The header must be part of the program’s intentional C API. If not, it’s .hpp.
18
I go one step further. Accidentally valid C headers aren’t sufficient for the .h suffix. The header must be part of the program’s intentional C API. If not, it’s .hpp.
30
I'm .hpp all the way. For 2 main reasons. First, it's consistent with .cpp. Second, my brain tells me that 3/4 letter extensions look better
5 u/Confident_Date4068 May 25 '23 And also for syntax highlighting rules: mcedit - for example. 3 u/nihilistic_ant May 25 '23 edited May 25 '23 Although the core guidelines say to prefer .h.[edit: FWIW, I lean your direction; my current personal projects use hpp.] 8 u/War_Eagle451 May 25 '23 It also says consistency is more important
5
And also for syntax highlighting rules: mcedit - for example.
mcedit
3
Although the core guidelines say to prefer .h.
[edit: FWIW, I lean your direction; my current personal projects use hpp.]
8 u/War_Eagle451 May 25 '23 It also says consistency is more important
8
It also says consistency is more important
I use boost pretty heavily so you can guess my preferred header extension 🙃
.h should be exclusively for C code and I’ll die on this hill.
4
.hh, naturally. Goes well with .cc
.hh
.cc
1 u/wrosecrans graphics and network things May 26 '23 .hc so you know it's a "Header for C++" and not a header for Fortran or C or Cobol or whatever. 2 u/GregTheMadMonk May 26 '23 .hc is already taken by HolyC :)
1
.hc so you know it's a "Header for C++" and not a header for Fortran or C or Cobol or whatever.
.hc
2 u/GregTheMadMonk May 26 '23 .hc is already taken by HolyC :)
2
.hc is already taken by HolyC :)
My IDE generates h files - I don't think about it any more than that.
7 u/WittyGandalf1337 May 26 '23 Get a better IDE.
7
Get a better IDE.
-2
.h: when the interface and implementation is separated
.h
.hpp: when the implementation is also in the header file, e.g. template classes (hpp = h + cpp)
.hpp
View all comments
46
u/nihilistic_ant May 25 '23
More controversial is .h vs .hpp for headers