Definition vs declaration

#include <stdio.h>

union test1;    // declaration

union test2 {  // The definition of union test2
    int a;
}

union test3 {   // The test4 definition of type union test3
    int b;
} test4;

declaration : 告訴 compiler 如何解讀 identifier,
及接受這個 reference of identifier,
也就是類似 extern int a;
translation unit 沒有定義 a,
所以先接受有 a,先 compile,
link 階段再連結。

definition of object : 在 memory 配置一塊 空間儲存其值,
link phase時, linker 會去連結變數。

definition 可以用在 define union test1,define object,不是每個定義,都會配置 memory:

posted @ 2017-03-26 19:04  wangchangruei  阅读(225)  评论(0编辑  收藏  举报