A CC file contains program source code written in C++ programming language. The contents of a CC file are saved as text. They include C++ commands and references to built-in/user-created libraries and modules.
A CPP file is a source code file written in C++, a popular programming language that adds features such as object-oriented programming to C. It may be a standalone program, containing all the code, or one of many files referenced in a development project.
KEY DIFFERENCEC is a Procedural Oriented language, whereas C++ is an Object-Oriented Programming language. C supports only Pointers whereas C++ supports both pointers and references. C does not allow you to use function overloading whereas C++ allows you to use function overloading.
This alternative etymology explains the frequent usage of "c:" when only one recipient is listed, while "cc:" is used for two or more recipients of the copies.
At the end of the day it doesn't matter because C++ compilers can deal with the files in either format. If it's a real issue within your team, flip a coin and move on to the actual work.
GNU GCC recognises all of the following as C++ files, and will use C++ compilation regardless of whether you invoke it through gcc or g++: .C
, .cc
, .cpp
, .CPP
, .c++
, .cp
, or .cxx
.
Note the .C
- case matters in GCC, .c
is a C file whereas .C
is a C++ file (if you let the compiler decide what it is compiling that is).
GCC also supports other suffixes to indicate special handling, for example a .ii
file will be compiled as C++, but not pre-processed (intended for separately pre-processed code). All the recognised suffixes are detailed at gcc.gnu.org
Great advice on which to use for the makefile and other tools, considering non-compiler tools while deciding on which extension to use is a great approach to help find an answer that works for you.
I just wanted to add the following to help with some .cc
vs .cpp
info that I found. The following are extensions broken down by different environments (from the "C++ Primer Plus" book):
Unix uses: .C
, .cc
, .cxx
, .c
GNU C++ uses: .C
, .cc
, .cxx
, .cpp
, .c++
Digital Mars uses: .cpp
, .cxx
Borland C++ uses: .cpp
Watcom uses: .cpp
Microsoft Visual C++ uses: .cpp
, .cxx
, .cc
Metrowerks CodeWarrior uses: .cpp
, .cp
, .cc
, .cxx
, .c++
The different environments support different extensions. I too was looking to answer this question and found this post. Based on this post I think I might go with .hpp
and .cpp
for ease of cross-platform/cross-tool recognition.
.cpp
is the recommended extension for C++ as far as I know. Some people even recommend using .hpp
for C++ headers, just to differentiate from C.
Although the compiler doesn't care what you do, it's personal preference.
I personally use .cc
extension for implementation files, .hh
for headers, and .inl
for inline/templates.
As said before, it is mainly a matter of taste.
From what I've seen, .cc
seems to be more "open source projects oriented", as it is advised in some great open source software coding styles, whereas .cpp
seems to be more Windowish.
--- EDIT
As mentioned, this is "from what i've seen", it may be wrong.
It's just that all Windows projects I've worked on used .cpp
, and a lot of open source projects (which are mainly on unix-likes) use .cc
.
Examples coding styles using .cc
:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With