• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            <2006年5月>
            30123456
            78910111213
            14151617181920
            21222324252627
            28293031123
            45678910

            統(tǒng)計

            • 隨筆 - 24
            • 文章 - 0
            • 評論 - 17
            • 引用 - 0

            常用鏈接

            留言簿(4)

            隨筆分類

            隨筆檔案

            相冊

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            有關(guān)include guard的一個好帖子(收藏)
            終于弄清楚了原來說的同一個頭文件不能被兩次或兩次以上包含是針對同一個源文件而言的。借用80后的流行語,真是漢哪!

            原貼地址:http://www.keil.com/forum/docs/thread10237.asp

            作者 Per Westermark

            The

            #ifndef xx
            #define xx
            ...
            #endif
            

            method is to make sure that a header file isn't included more than once from the same c file.

            You can not - and normally don't want to - stop multiple c files from including the same header file.

            A header file is included because:
            1) You have specifically added a line #include "xx" or #include <xx> in the source file. Don't do that unless you want the file to be included :)
            2) You are including one header file, that it it's turn (one or more steps away) includes another header file. But a header file should only contain a recursive #include if it really needs that other file for some declarations. Hence, you need to include it.

            What does this mean?

            If the header file must be seen by multiple source files, you can't use it to allocate global variables, since the linker would then complain about multiple sets of global variables with the same name. This can be solved with the following:

            //globals.h
            #ifndef _GLOBALS_H
            #define _GLOBALS_H
            #if defined MAIN
            #define EXTERN
            #else
            #define EXTERN extern
            #endif
            ...
            EXTERN int my_global_variable;
            #endif // _GLOBALS_H
            

            // main.c
            #define MAIN
            #include "globals.h"
            ...
            // misc.c
            #include "globals.h"
            ...
            

            In this case, only the inclusion in main.c will result in an "allocation" of global variables, because the #define EXTERN will be empty. All other source files that includes "globals.h" will just see the type information for the global variables.

            posted on 2009-02-19 09:04 小蔥蘸醬 閱讀(988) 評論(2)  編輯 收藏 引用

            評論

            # re: 有關(guān)include guard的一個好帖子(收藏) 2009-02-19 21:19 陳梓瀚(vczh)

            EXTERN的時候,如果剛好main沒有引用它,那就鏈接錯誤了- -#
              回復(fù)  更多評論    

            # re: 有關(guān)include guard的一個好帖子(收藏)[未登錄] 2009-02-20 16:15 小蔥蘸醬

            @陳梓瀚(vczh)
            歡迎評論!
            只要在include "globals.h"前定義了MAIN,就不會聯(lián)接錯誤,跟引用有什么關(guān)系呢?
              回復(fù)  更多評論    

            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            999久久久无码国产精品| 久久婷婷人人澡人人爽人人爱 | 性色欲网站人妻丰满中文久久不卡| 亚洲欧美成人久久综合中文网 | 影音先锋女人AV鲁色资源网久久| 人妻精品久久久久中文字幕一冢本| 成人国内精品久久久久影院| 久久精品国产亚洲7777| 久久天天躁狠狠躁夜夜躁2014| 国产91色综合久久免费| 久久久久亚洲精品男人的天堂| 久久久久久国产a免费观看黄色大片 | 国内精品伊人久久久久777| 久久综合综合久久狠狠狠97色88| 天堂无码久久综合东京热| 久久不射电影网| 少妇久久久久久久久久| 久久人妻少妇嫩草AV无码蜜桃| 99久久超碰中文字幕伊人| 久久中文字幕视频、最近更新| 久久精品国产只有精品2020| 伊人久久大香线蕉av一区| 久久精品国产亚洲5555| 久久综合久久综合久久综合| 久久99热只有频精品8| 人人妻久久人人澡人人爽人人精品| 亚洲国产精品久久久久| 国产精品免费看久久久| 亚洲AV无一区二区三区久久| 亚洲国产高清精品线久久| 久久精品国产99久久丝袜| 久久久久久狠狠丁香| 久久99精品久久久久婷婷| 青草国产精品久久久久久| 久久久久亚洲AV成人网人人网站| 少妇被又大又粗又爽毛片久久黑人| 国产精品99久久久久久宅男| 精品无码人妻久久久久久| 国产精品久久久久久久午夜片| 狠狠人妻久久久久久综合| 国产精品一区二区久久精品无码|