• 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.
    
  • 相关阅读:
    PL/SQL快捷键
    <c:if>条件判断 和 取值做乘法运算
    文档保存后找不到了误以为丢失,重做!
    Gson将参数放入实体类中进行包装之后再传递
    [leedcode 66] Plus One
    [leedcode 65] Valid Number
    [leedcode 64] Minimum Path Sum
    [leedcode 63] Unique Paths II
    [leedcode 62] Unique Paths
    [leedcode 61] Rotate List
  • 原文地址:https://www.cnblogs.com/pengdonglin137/p/15351251.html
Copyright © 2020-2023  润新知