• <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>
            <2009年2月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            1234567

            統計

            • 隨筆 - 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,就不會聯接錯誤,跟引用有什么關系呢?
              回復  更多評論    
            久久综合亚洲色HEZYO社区| 久久国产欧美日韩精品| 久久免费线看线看| 色综合合久久天天综合绕视看| 精品精品国产自在久久高清 | 一级做a爰片久久毛片16| 免费国产99久久久香蕉| 久久高清一级毛片| 漂亮人妻被中出中文字幕久久| 久久久久青草线蕉综合超碰 | 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 偷窥少妇久久久久久久久| 91精品国产高清久久久久久国产嫩草| 亚洲欧洲久久久精品| 久久久久久av无码免费看大片| 无码人妻精品一区二区三区久久 | 亚洲国产美女精品久久久久∴| 国产精品日韩欧美久久综合| 9999国产精品欧美久久久久久 | 色综合久久久久久久久五月| 日本精品久久久久中文字幕8| 99久久免费国产精品特黄| 国产精品禁18久久久夂久| 中文字幕无码久久精品青草| 国产亚洲综合久久系列| 中文精品久久久久人妻| 国产精品99久久久久久www| 性高湖久久久久久久久| 日韩电影久久久被窝网| 亚洲伊人久久大香线蕉苏妲己| 久久久久久精品久久久久| 久久久久国产精品三级网| 久久国产精品国产自线拍免费| 人妻无码久久一区二区三区免费| 久久亚洲精品无码观看不卡| 亚洲一区中文字幕久久| 好属妞这里只有精品久久| www.久久热.com| 国产69精品久久久久777| 国产一区二区三区久久| 国产精品岛国久久久久|