• include <xxx.h> 和 include "xxxx.h"的区别


    转载:https://stackoverflow.com/questions/21593/what-is-the-difference-between-include-filename-and-include-filename

    这是一个很基础的问题,但是网上的很多资料上并没有解释清楚,下面是从StackOverflow和GCC文档里截取出来的回答,很清楚的回答了这个问题。

    下面是StackOverflow上的回答:

    In practice, the difference is in the location where the preprocessor searches for the included file.

    For #include the preprocessor searches in an implementation dependent manner, normally in search directories pre-designated by the compiler/IDE. This method is normally used to include standard library header files.

    For #include "filename" the preprocessor searches first in the same directory as the file containing the directive, and then follows the search path used for the #include form. This method is normally used to include programmer-defined header files.

    A more complete description is available in the GCC documentation on search paths.

    下面是GCC文档中的说明:

    	2.3 Search Path
    By default, the preprocessor looks for header files included by the quote form of the directive #include "file" first relative to the directory of the current file, and then in a preconfigured list of standard system directories. For example, if /usr/include/sys/stat.h contains #include "types.h", GCC looks for types.h first in /usr/include/sys, then in its usual search path.
    
    For the angle-bracket form #include <file>, the preprocessor’s default behavior is to look only in the standard system directories. The exact search directory list depends on the target system, how GCC is configured, and where it is installed. You can find the default search directory list for your version of CPP by invoking it with the -v option. For example,
    
    cpp -v /dev/null -o /dev/null
    There are a number of command-line options you can use to add additional directories to the search path. The most commonly-used option is -Idir, which causes dir to be searched after the current directory (for the quote form of the directive) and ahead of the standard system directories. You can specify multiple -I options on the command line, in which case the directories are searched in left-to-right order.
    
    If you need separate control over the search paths for the quote and angle-bracket forms of the ‘#include’ directive, you can use the -iquote and/or -isystem options instead of -I. See Invocation, for a detailed description of these options, as well as others that are less generally useful.
    
    If you specify other options on the command line, such as -I, that affect where the preprocessor searches for header files, the directory list printed by the -v option reflects the actual search path used by the preprocessor.
    
    Note that you can also prevent the preprocessor from searching any of the default system header directories with the -nostdinc option. This is useful when you are compiling an operating system kernel or some other program that does not use the standard C library facilities, or the standard C library itself.
    
  • 相关阅读:
    win7系统如何一键清理系统垃圾【系统天地】
    win7无法正常关机的解决方法【系统天地】
    win10系统开机停在请稍候解决教程【系统天地】
    Win7系统一直提示盗版怎么办【系统天地】
    windows8 flash修复怎么操作【系统天地】
    win7电脑运行速度慢如何解决【系统天地】
    Win10系统如何自动清理垃圾缓存文件【系统天地】
    Win7启用NFS服务设置的方法【系统天地】
    win7系统获得管理员取得所有权的方法【系统天地】
    Ubuntu16.04+hadoop2.7.3环境搭建
  • 原文地址:https://www.cnblogs.com/pengdonglin137/p/15351251.html
Copyright © 2020-2023  润新知