C头文件中尖括号与双引号的区别

Posted miaoxiong

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C头文件中尖括号与双引号的区别相关的知识,希望对你有一定的参考价值。

2.1 Include Syntax

Both user and system header files are included using the preprocessing directive ‘#include’. It has two variants:

#include <file>

This variant is used for system header files. It searches for a file named file in a standard list of system directories. You can prepend directories to this list with the -I option (see Invocation).

#include "file"

This variant is used for header files of your own program. It searches for a file named file first in the directory containing the current file, then in the quote directories and then the same directories used for <file>. You can prepend directories to the list of quote directories with the -iquote option.

The argument of ‘#include’, whether delimited with quote marks or angle brackets, behaves like a string constant in that comments are not recognized, and macro names are not expanded. Thus, #include <x/*y> specifies inclusion of a system header file named x/*y.

However, if backslashes occur within file, they are considered ordinary text characters, not escape characters. None of the character escape sequences appropriate to string constants in C are processed. Thus, #include "x\n\\y" specifies a filename containing three backslashes. (Some systems interpret ‘\’ as a pathname separator. All of these also interpret ‘/’ the same way. It is most portable to use only ‘/’.)

It is an error if there is anything (other than comments) on the line after the file name.

摘抄自 https://gcc.gnu.org/onlinedocs/cpp/Include-Syntax.html#Include-Syntax

 

简单理解就是:

1. 尖括号告诉编译器去搜索系统目录,可使用 -I 选项添加其它搜索目录

2. 双引号告诉编译器先搜索源文件所在目录,其次搜索引号内的目录,最后搜索系统目录, -iquote 选项可添加其它目录到引号目录列表中。

 

以上是关于C头文件中尖括号与双引号的区别的主要内容,如果未能解决你的问题,请参考以下文章

SQL语言中的单引号与双引号区别

PHP中单引号与双引号的区别分析

在 C++ 中包含头文件时尖括号 < > 和双引号“”之间的区别? [复制]

ppq的面试题总结

单片机c语言中常用的头文件有哪些?分别有啥作用啊?

PHP教程:PHP中单引号与双引号的区别分析