作者littleshan (我要加入劍道社!)
看板C_and_CPP
標題Re: [問題] C語言 - Struct 在大型程式專案中的使用?
時間Sat Apr 4 10:53:10 2009
pc.h:
#ifndef PC_H
#define PC_H
struct pc {
int a;
int b;
};
struct pc2 {
int c;
int d;
};
extern struct pc pcgame;
extern struct pc2 pcgame2;
#endif // PC_H
main.c:
#include "pc.h"
struct pc pcgame = {1, 2};
struct pc2 pcgame2;
XXX.c:
#include "pc.h"
void f(void)
{
...
if(pcgame.a > pcgame.b){
...
}
pcgame2.c = rand();
...
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.121.113.53
推 uefang:推.. 簡單明瞭... 04/04 10:59
→ tsaiminghan:謝謝,看來我之前的寫法沒錯 04/04 11:00
→ littleshan:你對 pcgame 的初始化寫錯了,我才會回這篇 04/04 11:10
→ tsaiminghan:你指我xxxx.c那裡嗎? 我那邊不是想初始化,只是改值 04/04 11:33
→ tsaiminghan:只是沒寫function包起來,看來要寫清楚一些 04/04 11:36
→ tsaiminghan:補充一下,改值也要寫function,只是寫的時候想說簡單 04/04 11:40
→ tsaiminghan:寫個東西來代表可以在xxxx.c中操作 04/04 11:41