⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 incl.970507.html

📁 this is a mirrored site c-faq. thought might need offline
💻 HTML
字号:
<html><!-- Mirrored from c-faq.com/cpp/incl.970507.html by HTTrack Website Copier/3.x [XR&CO'2008], Sat, 14 Mar 2009 08:00:34 GMT --><head><title></title></head><body>[This is the first of a pair of articles I posted in 1997on the difference between <TT>#include&nbsp;""</TT>and <TT>#include&nbsp;&lt;&gt;</TT>,and strategies for using them;the second is<a href="incl.970605.html">here</a>.I have altered the text slightly for this web page.]<p>Newsgroups: comp.lang.c<br>From: scs@eskimo.com (Steve Summit)<br>Subject: Re: Quotes vs. angle brackets in #includes<br>Message-ID: &lt;E9tIv9.EJo@eskimo.com&gt;<br>Date: Wed, 7 May 1997 15:54:44 GMT<p>In article &lt;1997May5.182655.28400@relay.nswc.navy.mil&gt;,Donna Oliver writes:<br>&gt; Which is more maintainable, using angle brackets with the <TT>#include</TT><br>&gt; preprocessor directive or using the quotes?<p>They each have their uses.  For Standard headers, you alwayswant to use angle brackets.  For your own headers pertainingto a single, self-contained program, you almost always wantto use double quotes.  For third-party headers, or your ownheaders describing libraries which you use in multiple orlarge projects, there are viable (and acceptable) strategiesinvolving either angle brackets or double quotes (along withwhatever mechanisms your compiler provides for augmenting theheader file search path(s)).<p>&gt; Also, is the interpretation of the quotes system dependent?  That is,<br>&gt; can the preprocessor interpretation of ``current directory'' differ from <br>&gt; system to system?<p>Yes, very much so.  In particular, for some compilers/preprocessors,the ``current directory'' is always the directoryfrom which you invoked the compiler, but for others, it's thedirectory in which the file doing the <TT>#include</TT> resides (in otherwords, the directory containing the file containing the <TT>#include</TT>directive).  This latter strategy, though less obvious, is oftenexactly what you want (except, of course, when it isn't; it canbe a real nuisance under certain circumstances [<a href="#footnote">footnote</a>]).<p>&gt; I can not get any insight to this from the FAQ.<br><p>Question 10.8 mentions some of what I've discussed here.<p><address><a href="http://www.eskimo.com/~scs/">Steve Summit</a><br><a href="mailto:scs@eskimo.com">scs@eskimo.com</a></address><p><a name="footnote">[*]</a> For example, if you're working on a large, multi-personproject, and if there are central directories where the officialor at least main-line development versions of source and headerfiles reside, and individual ``playpen'' directories where eachteam member works with files prior to checking them back in tothe main source tree, and if header files can <TT>#include</TT> otherheader files, and if you've just checked out a header file intoyour own ``playpen'' include directory, modified it, and thenrecompiled, only to have your changes <em>not</em> take effect, it'slikely that the header file you modified is included, usingdouble quotes, by another header file, and that other header fileexists only in the central include directory, so that when anyother source file included that other header, the preprocessorretrieved the mainstream, unmodified version of that header, fromthe same ``current'' mainstream include directory, rather than theone you just modified.  In this case, you may have to check out acopy of that other header file, too, even though you have no needto modify it, just so it will be sitting in your private includedirectory, for other inclusions to find first and so that thesecondary header file it includes will be your modified copy.<p>I suppose this is another argument against nested include files.On the other hand, the problem as I've stated it only comes up ifyou use double quotes.  If you use angle brackets for the centralproject header files (in particular, for nested inclusions ofcentral project header files), the preprocessor never starts atthe wrong ``current'' directory, but always traverses the searchpath from the start again, and finds the one in your privateinclude directory, as you wanted, regardless.</body><!-- Mirrored from c-faq.com/cpp/incl.970507.html by HTTrack Website Copier/3.x [XR&CO'2008], Sat, 14 Mar 2009 08:00:34 GMT --></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -