What is the difference between .cc
and .cpp
file extensions?
From Google, I learned that they are both from the C++ language, but I am unsure of differences between them.
What is a C++ file? Files with CPP file extension are source code files for applications written in C++ programming language. A single C++ project may contain more than one CPP files as application source code.
Source code for a C++ program; may include all the code for a single program or may be one of several source code files referenced by a programming project; contains functions that are compiled into machine code, which the computer's operating system can understand.
Implementation files in C++ always have the file name extension " . cc ".
The short answer is that a . h file contains shared declarations, a . cpp file contains definitions and local declarations. It's important that you understand the difference between declarations and definitions.
Conventions.
Historically, the suffix for a C++ source file was .C
. This caused a few problems the first time C++ was ported to a system where case wasn't significant in the filename.
Different users adopted different solutions: .cc
, .cpp
, .cxx
and possibly others. Today, outside of the Unix world, it's mostly .cpp
. Unix seems to use .cc
more often.
For headers, the situation is even more confusing: for whatever reasons, the earliest C++ authors decided not to distinguish between headers for C and for C++, and used .h
.
This doesn't cause any problems if there is no C in the project, but when you start having to deal with both, it's usually a good idea to distinguish between the headers which can be used in C (.h
) and those which cannot (.hh
or .hpp
).
In addition, in C++, a lot of users (including myself) prefer keeping the template sources and the inline functions in a separate file. Which, while strictly speaking a header file, tends to get yet another set of conventions (.inl
, .tcc
and probably a lot of others).
In the case of headers it makes absolutely no difference to the compiler.
In the case of source files different endings will cause the compiler to assume a different language. But this can normally be overridden, and I used .cc
with VC++ long before VC++ recognized it as C++.
There is no difference. They're exactly the same.
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