<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                本文目錄 - [一、基本概念](http://www.cnblogs.com/mjios/archive/2013/03/20/2971575.html#label0) - [二、一般形式](http://www.cnblogs.com/mjios/archive/2013/03/20/2971575.html#label1) - [三、使用注意](http://www.cnblogs.com/mjios/archive/2013/03/20/2971575.html#label2) 說明:這個C語言專題,是學習iOS開發的前奏。也為了讓有面向對象語言開發經驗的程序員,能夠快速上手C語言。如果你還沒有編程經驗,或者對C語言、iOS開發不感興趣,請忽略 這講介紹最后一個預處理指令---文件包含 [回到頂部](http://www.cnblogs.com/mjios/archive/2013/03/20/2971575.html#labelTop) ### 一、基本概念 其實我們早就有接觸文件包含這個指令了, 就是#include,它可以將一個文件的全部內容拷貝另一個文件中。 [回到頂部](http://www.cnblogs.com/mjios/archive/2013/03/20/2971575.html#labelTop) ### 二、一般形式 ### 1.第1種形式#include <文件名> 直接到C語言庫函數頭文件所在的目錄中尋找文件 ### 2.第2種形式?#include "文件名" 系統會先在源程序當前目錄下尋找,若找不到,再到操作系統的path路徑中查找,最后才到C語言庫函數頭文件所在目錄中查找 [回到頂部](http://www.cnblogs.com/mjios/archive/2013/03/20/2971575.html#labelTop) ### 三、使用注意 1.#include指令允許嵌套包含,比如a.h包含b.h,b.h包含c.h,但是不允許遞歸包含,比如 a.h 包含 b.h,b.h 包含 a.h。 下面的做法是錯誤的 ![](https://box.kancloud.cn/2016-05-07_572d7679125cb.png) ?![](https://box.kancloud.cn/2016-05-07_572d7679289df.png) 2.使用#include指令可能導致多次包含同一個頭文件,降低編譯效率 比如下面的情況: ![](https://box.kancloud.cn/2016-05-07_572d767941501.png) ?![](https://box.kancloud.cn/2016-05-07_572d76795cb54.png) 在one.h中聲明了一個one函數;在two.h中包含了one.h,順便聲明了一個two函數。(這里就不寫函數的實現了,也就是函數的定義) 假如我想在main.c中使用one和two兩個函數,而且有時候我們并不一定知道two.h中包含了one.h,所以可能會這樣做: ![](https://box.kancloud.cn/2016-05-07_572d76797a2b6.png) 編譯預處理之后main.c的代碼是這樣的: ~~~ 1 void one(); 2 void one(); 3 void two(); 4 int main () 5 { 6 7 return 0; 8 } ~~~ 第1行是由#include "one.h"導致的,第2、3行是由#include "two.h"導致的(因為two.h里面包含了one.h)。可以看出來,one函數被聲明了2遍,根本就沒有必要,這樣會降低編譯效率。 為了解決這種重復包含同一個頭文件的問題,一般我們會這樣寫頭文件內容: ![](https://box.kancloud.cn/2016-05-07_572d767996b47.png) ![](https://box.kancloud.cn/2016-05-07_572d7679ae3d7.png) 大致解釋一下意思,就拿one.h為例:當我們第一次#include "one.h"時,因為沒有定義_ONE_H_,所以第9行的條件成立,接著在第10行定義了_ONE_H_這個宏,然后在13行聲明one函數,最后在15行結束條件編譯。當第二次#include "one.h",因為之前已經定義過_ONE_H_這個宏,所以第9行的條件不成立,直接跳到第15行的#endif,結束條件編譯。就是這么簡單的3句代碼,防止了one.h的內容被重復包含。 這樣子的話,main.c中的: ~~~ #include "one.h" #include "two.h" ~~~ 就變成了: ~~~ 1 // #include "one.h" 2 #ifndef _ONE_H_ 3 #define _ONE_H_ 4 5 void one(); 6 7 #endif 8 9 // #include "two.h" 10 #ifndef _TWO_H_ 11 #define _TWO_H_ 12 13 // #include "one.h" 14 #ifndef _ONE_H_ 15 #define _ONE_H_ 16 17 void one(); 18 19 #endif 20 21 void two(); 22 23 #endif ~~~ 第2~第7行是#include "one.h"導致的,第10~第23行是#include "two.h"導致的。編譯預處理之后就變為了: ~~~ 1 void one(); 2 void two(); ~~~ 這才是我們想要的結果
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看