.cc 和 .cpp 文件后缀有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18590135/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between .cc and .cpp file suffix?
提问by lv_laker
What is the difference between .ccand .cppfile extensions?
.cc和.cpp文件扩展名有什么区别?
From Google, I learned that they are both from the C++ language, but I am unsure of differences between them.
从谷歌,我了解到它们都来自 C++ 语言,但我不确定它们之间的区别。
回答by James Kanze
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.
过去,C++ 源文件的后缀是.C. 这在第一次将 C++ 移植到文件名中大小写不重要的系统时引起了一些问题。
Different users adopted different solutions: .cc,
.cpp, .cxxand possibly others. Today, outside of the Unix
world, it's mostly .cpp. Unix seems to use .ccmore often.
不同的用户采用了不同的解决方案:.cc,
.cpp,.cxx可能还有其他解决方案。今天,在 Unix 世界之外,它主要是.cpp. Unix 好像用的.cc比较多。
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.
对于头文件,情况更令人困惑:无论出于何种原因,最早的 C++ 作者决定不区分 C 和 C++ 的头文件,并使用.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 (.hhor .hpp).
如果项目中没有 C,这不会导致任何问题,但是当您开始不得不同时处理这两者时,通常最好区分 C 中可以使用的头文件 ( .h) 和不能使用的头文件(.hh或.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, .tccand probably a lot of
others).
此外,在 C++ 中,很多用户(包括我自己)更喜欢将模板源和内联函数保存在单独的文件中。其中,虽然严格来说是头文件,但往往会得到另一组约定(.inl,.tcc可能还有很多其他约定)。
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 .ccwith VC++ long before VC++ recognized it as C++.
在源文件的情况下,不同的结尾将导致编译器采用不同的语言。但这通常可以被覆盖,并且我.cc在 VC++ 将其识别为 C++ 之前很久就使用了 VC++。
回答by Alon Gubkin
There is no difference. They're exactly the same.
没有区别。他们完全一样。
回答by Dentoid
Technically for the compiler there is no difference. However, some compilers and/or build systems will guess how to compile your files based on the extension and may or may not detect "cc" (or "cpp" but that is more rare I guess) as a c++ file.
从技术上讲,编译器没有区别。但是,一些编译器和/或构建系统会根据扩展名猜测如何编译您的文件,并且可能会或可能不会将“cc”(或“cpp”,但我猜这更罕见)检测为 c++ 文件。
回答by Bodhi
Actually it all depends on what you and your compiler prefer. There is no difference between them at all.
实际上,这完全取决于您和您的编译器的喜好。它们之间完全没有区别。

