• <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年6月>
            28293031123
            45678910
            11121314151617
            18192021222324
            2526272829301
            2345678

            統(tǒng)計(jì)

            • 隨筆 - 24
            • 文章 - 0
            • 評(píng)論 - 17
            • 引用 - 0

            常用鏈接

            留言簿(4)

            隨筆分類

            隨筆檔案

            相冊(cè)

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

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

            原貼地址: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 小蔥蘸醬 閱讀(987) 評(píng)論(2)  編輯 收藏 引用

            評(píng)論

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

            EXTERN的時(shí)候,如果剛好main沒(méi)有引用它,那就鏈接錯(cuò)誤了- -#

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

            @陳梓瀚(vczh)
            歡迎評(píng)論!
            只要在include "globals.h"前定義了MAIN,就不會(huì)聯(lián)接錯(cuò)誤,跟引用有什么關(guān)系呢?

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


            久久婷婷是五月综合色狠狠| 久久综合久久鬼色| 蜜臀久久99精品久久久久久小说| 波多野结衣AV无码久久一区| 久久久无码一区二区三区| 久久se精品一区二区| 久久久久国色AV免费看图片| 久久九九兔免费精品6| www.久久热.com| 偷偷做久久久久网站| 99久久精品国产麻豆| 久久综合亚洲色一区二区三区| 久久精品国产亚洲av高清漫画| 香蕉99久久国产综合精品宅男自 | 精品久久无码中文字幕| 国产亚洲精品自在久久| 一级做a爰片久久毛片看看| AV色综合久久天堂AV色综合在| 亚洲人成无码www久久久| 久久国产精品99久久久久久老狼 | 99久久国产主播综合精品| 99久久夜色精品国产网站| 久久久久一级精品亚洲国产成人综合AV区 | 午夜视频久久久久一区| 51久久夜色精品国产| 久久99精品久久久久久hb无码| 亚洲美日韩Av中文字幕无码久久久妻妇| 久久99国产精品久久99| 久久精品国产第一区二区三区| 久久只这里是精品66| 久久涩综合| 久久久久亚洲AV成人网| 99久久国产主播综合精品| 日本一区精品久久久久影院| 国产精品久久久久久久久免费| 狠狠色丁香久久婷婷综合五月| 亚洲国产欧美国产综合久久| 狠狠色狠狠色综合久久| 欧美噜噜久久久XXX| 久久ww精品w免费人成| 精品午夜久久福利大片|