简体   繁体   English

不同类型的C / C ++头文件之间有什么区别

[英]What are the difference between different types C/C++ header files

In the most tradition way, c/c++ uses .h for header file extensions. 按照最传统的方式,c / c ++将.h用作头文件扩展名。 However, in the realworld usage (ie Visual C++), there are many other types of header files, such as: .hxx , .hh , .w , .idl , etc. 但是,在实际使用中(即Visual C ++),还有许多其他类型的头文件,例如: .hxx.hh.w.idl等。

My question is, why people need different types of header files? 我的问题是,为什么人们需要不同类型的头文件? I don't have a complete list of all the header types I saw, but please pick any case you familiar with and explain a bit. 我没有我看到的所有标头类型的完整列表,但是请选择您熟悉的任何情况并进行一些说明。

For the compiler there's no difference. 对于编译器而言,没有区别。 You can use the extension that you want, or even no extension at all. 您可以使用所需的扩展名,甚至可以根本不使用任何扩展名。 So, .hh , .hxx , .my_awesome_extension are valid. 因此, .hh.hxx.my_awesome_extension有效。 The only important thing for the compiler is that it can find a file with the name you specify. 对于编译器而言,唯一重要的事情是它可以找到具有您指定名称的文件。

The compiler don't care about the extension, but most of code-editors do and will switch to C++ mode if they encounter one of these extension. 编译器并不关心扩展,但是大多数代码编辑器都会这样做,如果遇到这些扩展之一,它们将切换到C ++模式。

For instance Emacs will use c-mode with .h extension while switching to c++-mode with .hpp extension. 例如,Emacs将使用扩展名为.h c-mode ,同时切换到扩展名为.hpp c++-mode

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM