Is there any reason Google uses the cc extension instead of the standard cpp in their open source projects? Should I do that too?
-
To me, `.cpp` makes more sense to be consistent with `.hpp` – Elijah Mock Jan 18 '23 at 02:46
5 Answers
It's entirely a matter of personal preference, at least for the person(s) starting the project. Whatever you choose, be consistent.

- 22,781
- 4
- 49
- 67
-
6The gcc man page lists multiple extensions which are, "C++ source code which must be preprocessed", including these two. – TomWilsonFL Jun 30 '10 at 04:54
There are 4 main extensions used for C++ source code:
.C
(upper-case C).cpp
.cxx
.cc
Choose whichever makes the most sense for you, and expect to have to deal with problems on some other platforms.
Of these choices, the one I listed first is most problematic. Both Windows and MacOS X (by default) have case-preserving but case-insensitive file systems. That means that 'file.c
' and 'file.C
' (and, indeed, 'FILE.C
') are names for the same file.
If you have plans to work with Google code, you might want to follow the Google convention.

- 730,956
- 141
- 904
- 1,278
Consistency. Nothing more. The extensions ".cpp", ".cxx", ".cc", and ".C" are all valid extensions for C++ source files (although you should avoid ".C" as it can lead to problems on filesystems that are case-insensitive but case-preserving, like those of Mac OS X and Windows). Similarly, ".h" and ".hpp" are common extensions for C++ headers. In my experience ".cpp" and ".h" are the most common, and those are the ones that I would typically recommend for new projects. If you are adding to an existing project, you should use whatever convention exists for that project (e.g. you would use ".hpp" in Boost).

- 93,612
- 16
- 138
- 200
-
1Good reasons for .hpp: http://stackoverflow.com/questions/152555/h-or-hpp-for-your-class-definitions/152671#152671 – ergosys Nov 04 '11 at 19:53
There is no standard extension for C++ source files. There are some commonly used extensions but you're free to use any that you want assuming your toolset supports it (don't know of one that doesn't). You could postfix all your C++ source files with .html if you wanted.

- 40,307
- 7
- 73
- 125
Typing .cc is quite a bit easier than .cpp, and for all other purposes they're equivalent. So, yes.

- 2,249
- 16
- 21
-
5
-
2@Craig: Not even then, consider the cost of typing one extra letter in the name as compared to typing the contents of the file itself... That must be negligible. – David Rodríguez - dribeas Jun 30 '10 at 07:10
-
i don't think anyone with a nearly tech related job would find matter to press an extra more key. At the end c++ extensions are just a matter of style. – Giuppox Mar 29 '21 at 09:39