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ํ•˜๋Š”๊ฑฐ๋ž‘ ์™„์ „ํžˆ ๋™์ผํ•œ ๊ธฐ๋Šฅ์ž„.