打印

Keil C51包含文件include进行搜索的顺序到底是如何?

[复制链接]
5183|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
云上华仙|  楼主 | 2013-8-16 11:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
   

这里这样解释:(下面是我翻译的)
--------------------------------------------------------------------------
#include
主页» 预处理器 » 预处理器指令 » #include
#include 指令使得C预处理器在编译中包含指定文件的内容,然后继续处理当前文件剩下的内容。#include 指令可能用于指定两种类型的头(或包含)文件:系统头文件和用户头文件。
系统头文件如下被包含:
#include <filename>

这些包含文件被包含在\INC\文件夹下。它们是keil开发工具的一部分,且不应该被修改。当一个系统头文件被指定,编译器从下列文件夹按序搜索。
· INCDIR 指令指定的路径。
· C51INC 环境变量指定的路径.

用户头文件如下被包含:
#include "filename"

这些包含文件是用户创建的,可能存在于电脑的任何位置。当一个用户头文件被指定,编译器按照如下次序搜索文件夹:
· 当前文件夹。
· 源文件夹。
· INCDIR 指令指定的路径。
· C51INC 环境变量指定的路径.



相关帖子

沙发
云上华仙|  楼主 | 2013-8-16 11:12 | 只看该作者
但是,在一个技术支持的**里面,写着的意思不同。
请看下面:http://www.keil.com/support/docs/2393.htm
-------------------------------------------------------------------------

GENERAL: DIFFERENCES BETWEEN #INCLUDE <FILE> AND "FILE"
Information in this article applies to:

C166 Version 4

C251 Version 3

C51 Version 6 and Higher


SYMPTOMS
If you copy an include file from the \KEIL\Cxx\INC folder to your
project folder and attempt to include it using:#include <filename.h>

the original file from the \INC folder is included instead of the
copy.
CAUSE
This is correct behavior. The ANSI standard differentiates between#include <filename>

and#include "filename"

The ANSI standard does not specify a search order but recommends that
#include <filename> should search implementation-defined locations
for header files.
In the Keil C compiler (and most other C compiler implementations) the
include file search is implemented as follows:



#include <> searches for filename in the directories
specified with the INCDIR compiler directive. If this search fails, paths
specified by the C51INC, C166INC or C251INC environment
variable are used. If this fails the current folder (the folder where the
project file is stored) is used. If this fails, the C source file folder is
used.

#include "filename" searches for filename in the
current folder. If this search fails, the C source folder is used. If this
fails, the compiler proceeds as if you wrote #include <>.

In the µVision IDE, you may view or change the search path the compiler uses
for #include <> statements. From the Project window, click on
Project, then Components, Environment, Books to display the
Components, Environment, Books dialog. Clicking on the
Folders/Extensions tab displays the folders searched by the compiler,
assembler and linker. The compiler uses the path name in INC text box for
#include <> statements.
RESOLUTION
Use the following preprocessor directive to include your modified header
file.#include "filename.h"
--------------------------------------------------------------------------------------------------

使用特权

评论回复
板凳
云上华仙|  楼主 | 2013-8-16 11:13 | 只看该作者
本帖最后由 云上华仙 于 2013-8-16 11:19 编辑

但是,在一个技术支持的**里面,写着的意思不同。
请看下面:http://www.keil.com/support/docs/2393.htm
-------------------------------------------------------------------------

关键是这里,我觉得说的不对。
---------------------------------------------------------------


#include <> searches for filename in the directories
specified with the INCDIR compiler directive. If this search fails, paths
specified by the C51INC, C166INC or C251INC environment
variable are used. If this fails the current folder (the folder where the
project file is stored) is used. If this fails, the C source file folder is
used.
这里说尖括号是按照INCDR指令指定路径、C51INC环境变量指定路径、当前工程文件夹、源文件夹
进行搜索 。

#include "filename" searches for filename in the
current folder. If this search fails, the C source folder is used. If this
fails, the compiler proceeds as if you wrote #include <>.
这里说双引号是按照当前工程文件夹、源文件夹、
INCDR指令指定路径、C51INC环境变量指定路径进行搜索。

--------------------------------------------------------------------
这里意思是:用尖括号搜索完系统的文件夹,如果没有,还会到用户文件夹里面找?
这样跟我以前理解的不一样。是否这篇**写错了。
我的理解是:尖括号只能在系统INCDR指令指定路径、C51INC环境变量指定路径进行搜索 ,而不能在当前工程文件夹、源文件夹进行搜索。
双引号的范围是:按照当前工程文件夹、源文件夹、
INCDR指令指定路径、C51INC环境变量指定路径进行搜索。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:行成于思毁于随。

22

主题

84

帖子

1

粉丝