• <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>
            <2025年6月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            293012345

            統計

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

            常用鏈接

            留言簿(4)

            隨筆分類

            隨筆檔案

            相冊

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            有關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 小蔥蘸醬 閱讀(994) 評論(2)  編輯 收藏 引用

            評論

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

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

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

            @陳梓瀚(vczh)
            歡迎評論!
            只要在include "globals.h"前定義了MAIN,就不會聯接錯誤,跟引用有什么關系呢?
              回復  更多評論    
            亚洲综合伊人久久大杳蕉| 午夜久久久久久禁播电影| 色欲久久久天天天综合网精品| 无码AV中文字幕久久专区| 久久精品国产亚洲AV嫖农村妇女 | 亚洲国产婷婷香蕉久久久久久| 亚洲午夜精品久久久久久浪潮| 欧美牲交A欧牲交aⅴ久久| 欧美一区二区精品久久| 久久久久久久久久久精品尤物 | 久久亚洲国产精品成人AV秋霞| 欧美熟妇另类久久久久久不卡| 久久久久一级精品亚洲国产成人综合AV区| 亚洲国产成人久久笫一页| 国产欧美一区二区久久| 久久综合九色欧美综合狠狠| 久久婷婷五月综合97色一本一本| 久久综合伊人77777麻豆| 久久久久国产精品| 人妻无码中文久久久久专区 | 日韩欧美亚洲综合久久| 国产农村妇女毛片精品久久| 麻豆成人久久精品二区三区免费 | 亚洲AV成人无码久久精品老人| 久久人妻少妇嫩草AV无码蜜桃| 狠狠狠色丁香婷婷综合久久五月| 国产精品99久久久精品无码| 久久久久久av无码免费看大片| 久久国产精品成人免费| 久久精品国产亚洲AV大全| 久久婷婷国产剧情内射白浆 | 久久午夜无码鲁丝片| 成人久久免费网站| 亚洲中文字幕久久精品无码APP| 久久久久亚洲精品天堂久久久久久| 国产精品久久久久久久久久免费| 久久精品国产精品亚洲精品| 久久久久久九九99精品| 蜜臀久久99精品久久久久久小说| 久久久久亚洲AV无码麻豆| 久久综合给合久久狠狠狠97色|