Whats the difference between using CC and CPP as the file extension for C++ programs? I thought C++ use the CPP extension for source files. I was reading this article and saw he used CC.

http://community.linuxmint.com/tutorial/view/111

Dani AI

Generated

Short answer: the extension is a convention for tools and people, not a language feature. asked the right question; as and pointed out, toolchains and editors decide how to treat a file. That leaves several practical points worth knowing that this thread hasn't covered.

Pick one extension and stay consistent across a project. Editors, IDEs, build systems and teammate expectations matter more than the suffix itself. Avoid using a capital .C because case sensitivity differs between Unix and Windows filesystems and that can cause confusing behavior. If you join an existing codebase, follow its style rules (many projects document their preferred suffix).

If you need to force a compiler to treat a file as C++, do it with the tool rather than renaming files. Example with GCC/Clang:

g++ -std=c++17 -Wall -Wextra -O2 -o myprog myfile.cpp

# treat a nonstandard extension as C++
g++ -x c++ -std=c++17 -o myprog myfile.custom

For build systems: tell CMake/Make about unusual extensions rather than relying on heuristics (e.g., set source properties or explicit rules). Keep header naming consistent too (choose .hpp or .h and stick with it). In short: there’s no semantic difference in the language — choose what fits your team and toolchain, document it, and use build-tool overrides when you must.

Recommended Answers

All 3 Replies

Its compiler dependent -- compilers are free to use any extension they please. Microsoft uses *.cpp, while g++ and MinGW use *.cc, although both compilers can be set up to recognize other extensions.

[snipped]
Oops, how did I end up posting here? This is the wrong thread!
Sorry about that!

I believe G++ recognizes .cc, .c++, .cpp files.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.