.c vs .cc vs. .cpp vs .hpp vs .h vs .cxx [closed] from http://stackoverflow.com/questions/5171502/c-...

本文探讨了C++源代码及头文件扩展名的历史演变,包括.c、.cpp、.cxx等不同扩展名的使用背景及其原因。文章还介绍了如何区分C与C++的文件,以及标准库头文件的命名习惯。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Possible Duplicates:
*.h or *.hpp for your class definitions
Correct C++ code file extension? .cc vs .cpp

I used to think that it used to be that:

  • .h files are header files for C and C++, and usually only contain declarations.
  • .c files are C source code.
  • .cpp files are C++ source code (which can also be C source code).

then files like .hpp.cc, and .cxx came along, and I got totally confused... what's the difference(s) between those? When do you use the "new" ones?

 

 

 

Historically, the first extension used for C++ were .c and .h, exactly like for C. This caused practical problems, especially the .c which didn't allows build system to easily differentiate C++ and C files.

Unix, on which C++ has been developed, has case sensitive file systems. So some used .C for C++ files. Other used .c++, .cc and .cxx. .C and .c++ have the problem that they aren't available on other file systems and their use quickly dropped. DOS and Windows C++ compilers tended to use .cpp, and some of them make the choice difficult, if not impossible, to configure. Portability consideration made that choice the most common, even outside windows.

Headers have used the corresponding .H, .h++, .hh, .hxx and .hpp. But unlike the main files, .h remains to this day a popular choice for C++ even with the disadvantage that it doesn't allow to know if the header can be included in C context or not. Standard headers have now no extension at all.

Additionally, some are using .ii, .ixx, .ipp, .inl for headers providing inline definitions and .cxx, .cpp, .txx, .tpp and .tpl for template definitions. Those are either included in the headers providing the definition, or manually in the contexts where they are needed.

Compilers and tools usually don't care about what extensions are used, but using a extension that they associate with C++ prevents the need to track out how to configure them so they correctly recognise the language used.

 

转载于:https://www.cnblogs.com/songtzu/archive/2012/12/21/2827651.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值