Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between .cc and .cpp file suffix? [duplicate]

Tags:

c++

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.

like image 420
lv_laker Avatar asked Sep 03 '13 10:09

lv_laker


People also ask

What does .cpp file mean?

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.

What is the .cc file?

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.

What is the suffix of a C++ file?

Implementation files in C++ always have the file name extension " . cc ".

What is the difference between a .cpp file and a .h file?

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.


2 Answers

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++.

like image 142
James Kanze Avatar answered Sep 28 '22 08:09

James Kanze


There is no difference. They're exactly the same.

like image 26
Alon Gubkin Avatar answered Sep 28 '22 08:09

Alon Gubkin