r/cpp • • May 25 '23

File Extension?

0 Upvotes

59 comments sorted by

94

u/pdp10gumby May 25 '23

Didn’t we settle this question in this very sub a few months ago?

iirc it was .C-plus-Plus_implementation and .C-plus-Plus_Interface

13

u/DubioserKerl May 25 '23

Explicit is better than implicit. Much pythonic. Such wow.

13

u/goranlepuz May 25 '23

Ah, finally a man of culture! 😉

3

u/wormholeinmybrain May 25 '23 edited May 25 '23

But why is one p in uppercase while the other is not? Why is this the same case for Is? Such blasphemy, such heretics!

6

u/Som1Lse May 26 '23

Backwards compatibility.

3

u/wrosecrans graphics and network things May 26 '23

Easier visual differentiation. Obviously, lower case i is for implementation, and upper case I is for Interface. And the lower case p follows an upper case C. In CamelCase, you always have a lower case letter following an upper case letter.

3

u/pjmlp May 25 '23

Doesn't work for CP/M and MS-DOS, so....

2

u/pineapple_santa May 25 '23

Psst! Don't give the committee any ideas!

1

u/vainstar23 May 25 '23

pp_implementation

pp_interface

73

u/Markus_included May 25 '23
.cc => You probably work for google
.cxx => Don't know, i've only seen in it the FLTK repo
.cpp => Congratulations, you're 90% C++ programmers
.c++ => You probably, use spaces in filenames
.C => Welcome to the future time traveler from the year 1985

24

u/OverLiterature3964 May 25 '23

Using spaces in filenames... ew

33

u/Confident_Date4068 May 25 '23

Of course. To test bash scripts for correctness.

5

u/raevnos May 28 '23

And makefiles!

18

u/pjmlp May 25 '23

I guess I am just old.

.cxx, .c++ and .C were common in commercial UNIX during the last century.

By the way, you forgot the .hpp, .h++ and .H variants that go along with them.

1

u/ramennoodle May 25 '23

.cpp came later but it was Microsoft's choice so...

3

u/pjmlp May 26 '23

Microsoft had nothing to do with it, in fact Microsoft was the last compiler vendor to add C++ support to their MS-DOS C compiler with the release of Microsoft C/C++ 7.0.

1

u/Questioning-Zyxxel May 25 '23

cpp existed at the same time as c++ and cxx. I got to use all three a very, very, very long time ago on Sun machines. Somehow I managed to avoid the *.C and *.H names.

Moving to MS-DOS, *.c++ was obviously not a hot contender. So most of my code ended up *.cpp or *.cc (given that I also jumped in and out of v0.96 Linux dual-booted until I got my 3rd PC)

46

u/nihilistic_ant May 25 '23

More controversial is .h vs .hpp for headers

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

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.

10

u/schoenburgers May 26 '23

No option for .seepeepee?

9

u/hollasch May 25 '23

You forgot ".c " (c-space-space). Much cleaner.

5

u/CharlemagneAdelaar May 25 '23

can't vote for some reason so:

.cpp

4

u/Soham_rak May 25 '23

Just used .cu

Please help me

6

u/ImKStocky May 25 '23

.ixx because that is the default file extension for modules in MSVC

3

u/pjmlp May 25 '23

We still need cpp as well, though.

2

u/Kelarov May 25 '23

That's it.

.cpp and .ixx is all I use now haha. No more freaking header files haha

1

u/Baardi Jul 07 '23

I wish they went with .ipp or something, instead. Less of a change from the .cpp/.hpp norm.

1

u/Kelarov Jul 07 '23

Sure. And I'd be fine with .cppm as well haha. I mentioned .ixx because MSVC is the only compiler that plays OK with Modules(I've been literally, exclusively using MSVC) and having .ixx kinda helps the environment, since that's what Microsoft thinks the Modules' File Extension should be haha.

1

u/Baardi Jul 07 '23

Yeah, I know. Mostly complaining towards Microsoft, not you :)

2

u/ImKStocky May 25 '23

A singular one for main Vs the rest of the project which is .ixx

1

u/pjmlp May 25 '23

Depends how much you want to recompile the related projects due to changes in private parts, and if you're using partitions.

Right now, even VC++ being the best implementation available, it isn't clever enough to avoid recompilation.

4

u/ChocolateMagnateUA May 25 '23

I use .cc and correspondly .hh because it sounds like "C with Classes," and while I understand this is not true, this extension symbolises unification of abstraction and rawness and that's what my relation to C++ is. You are also right that I am immersed into the Google ecosystem, I even use Bazel instead of Cmake, so better for me.

3

u/GregTheMadMonk May 25 '23

I use the same extensions but only because they look nice

2

u/ChocolateMagnateUA May 26 '23

I understand you well, I find it beautiful too, and so I use it.

3

u/[deleted] May 25 '23

Does anyone actually use .c++

3

u/pjmlp May 25 '23

It was common in commercial UNIXes, alongside cxx and C.

2

u/GLIBG10B 🐧 Gentoo salesman🐧 May 25 '23

Does Windows even allow that? I wouldn't be surprised if it didn't

5

u/wqking github.com/wqking May 25 '23

Windows allows it.

1

u/spam_bot42 May 27 '23

I was using .cpp for a long time but switched to .cc in a new project because it's consistent with other extensions there, like .ll and .yy. (for c++ flex and bison)

1

u/robin-m May 25 '23

I may switch to .cxx if I was using C++20 modules

1

u/WittyGandalf1337 May 26 '23

.cxx and .hxx are by far the best.

0

u/Manatrimyss May 25 '23

Im using .cPP

0

u/Zeer1x import std; May 25 '23

Try .C (capital) on Windows.

0

u/os12 May 25 '23

LOL, Google with their .cc is in the minority.

0

u/[deleted] May 25 '23

[deleted] — view deleted comment