• <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>
            <2007年7月>
            24252627282930
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234

            統(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 小蔥蘸醬 閱讀(987) 評論(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   管理


            久久福利青草精品资源站免费| 国产精品美女久久久久久2018| 久久99精品国产99久久6男男| 青青草原综合久久大伊人精品| 久久AⅤ人妻少妇嫩草影院| 亚洲午夜精品久久久久久app| 色狠狠久久AV五月综合| 漂亮人妻被中出中文字幕久久| 一本久久a久久精品综合香蕉| 久久99精品久久久久久久不卡 | 久久香蕉国产线看观看精品yw| 精品久久久久久无码中文字幕一区| 国产成人综合久久精品尤物| 国内精品人妻无码久久久影院导航| 成人国内精品久久久久影院VR | 久久久久无码精品国产| 精品久久久久久99人妻| 久久亚洲中文字幕精品有坂深雪| 久久热这里只有精品在线观看| 国产高清美女一级a毛片久久w| 久久er99热精品一区二区| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 亚洲中文久久精品无码| 亚洲欧美精品一区久久中文字幕 | 亚洲国产成人精品女人久久久 | MM131亚洲国产美女久久| 久久WWW免费人成一看片| 色综合合久久天天给综看| 色综合久久综合网观看| 2021少妇久久久久久久久久| 男女久久久国产一区二区三区| 精品国产乱码久久久久久呢| 少妇无套内谢久久久久| 久久久精品国产| 久久人妻AV中文字幕| 久久综合精品国产一区二区三区| 丁香久久婷婷国产午夜视频| 99久久国产综合精品五月天喷水| 久久99精品久久久久久野外| 亚洲国产精品一区二区久久| 色综合久久中文色婷婷|