global.c
---------------------------
int player_hp = 0;
a.c
-------------------------------
extern int player_hp;
b.c
--------------------------------
extern int player_hp;
์์ฒ๋ผ ๋งค๋ฒ player_hp ๋ฅผ ์จ์ผํ๋ ์์คํ์ผ์์ extern int player_hp๋ฅผ ์จ์ค์ผ ํจ.
๊ทธ๋์ ์ด๊ฑธ ๊ฐํธํ๊ฒ ํ๊ธฐ ์ํด์
global.h
--------------------------------
extern int player_hp;
a.c
-----------------------------
include "global.h"
b.c
------------------------------
include "global.h"
include ๊ตฌ๋ฌธ์ ์คํ์ ํ ์คํธ๋ฅผ copy and paste ํ๊ฒํ๊ณ ๋๊ฐ์ ํจ๊ณผ์.
๊ฐ๋ น
a.c ์์
include "global.h" ๊ฐ ์ด๋ป๊ฒ ํด์๋๋์ง ๋ชจ๋ฅด๊ฒ ์ผ๋ฉด
global.h ํ์ผ์ ๋ชจ๋ ์์ค๋ฅผ ๋ค ๋ณต์ฌํด์ย
include "global.h" <--- ์ ์์น์ ๋์ ๋ถ์ฌ๋ฃ๊ธฐ ํด๋ณด๋ฉด๋จ.
์ฆ, include ์ฐ๋๊ฑฐ๋ copy and pasteํ๋๊ฑฐ๋ ์์ ํ ๋์ผํ ๊ธฐ๋ฅ์.
๊ฐ์ฌ๋๋ฆฝ๋๋ค ์ฑ๋!
ํ๋ ๊ทธ๋ ๋ค๋ฉด global.c์์ #define STR_SIZE 20๋ผ๊ณ ํด๋จ๋๋ฐ, ์ด๋ฐ ์์๊ฐ๋ extern ์ฒ๋ฆฌ ๊ฐ๋ฅํ๊ฐ์?
์ด๊ฒ๋ ๋๊ธ๋ก ๋ตํ๊ธฐ ์ข ๋ต๋ตํ๋ฐ ๊ธ ์๋ก ํ๊ฒ ์
๋๋ฌด ๊ฐ์ฌ๋๋ฆฝ๋๋ค ์ฑ๋