C++ code file extension? .cc vs .cpp


Question

I have seen C++ code saved as both .cc and .cpp files. Is there a difference between the two?

The Google style guide seems to suggest .cc, but provides no explanation.

I am mainly concerned with programs on Linux systems.

1
523
2/27/2017 9:40:10 AM

Accepted Answer

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.

622
3/14/2015 7:03:09 PM

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


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon