[問題] 用keil C 一個更動全域結構的函數編不過去...

看板C_and_CPP (C/C++)作者 (行在自我上)時間15年前 (2011/03/25 14:56), 編輯推噓2(208)
留言10則, 3人參與, 最新討論串1/1
開發平台(Platform): KEIL C (寫8051程式的) 問題(Question):一個改變全域結構的函數無法編譯 餵入的資料(Input): struct Helth { char LV; char MaxHP; char MaxMP; char Atk; char Def; char HP; char MP; int UpLVEXP; int EXP; }; /*以上為在main外宣告的陣列 void UpLV(int NewLV) { int i; Helth.LV =NewLV; Helth.Atk =NewLV*10; Helth.Def =NewLV*10; Helth.MaxHP =NewLV*20; Helth.MaxMP =NewLV*20; .............................(這是要改變結構數值的函數) 預期的正確結果(Expected Output): 編譯產生執行檔 錯誤結果(Wrong Output): error C202: 'Helth': undefined identifier error C202: 'Helth': undefined identifier error C202: 'Helth': undefined identifier error C202: 'Helth': undefined identifier error C202: 'Helth': undefined identifier Target not created /*行數顯示是在函數內出錯 我想知道我到底錯在哪裡..... 程式碼(Code):(請善用置底文網頁, 記得排版) 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.115.236.24

03/25 14:57, , 1F
在 void UpLV 前面加一行 struct Helth Helth;
03/25 14:57, 1F

03/25 15:01, , 2F
好像可以編過去了 謝謝 想請教 這寫法的用意是什麼?
03/25 15:01, 2F

03/25 15:03, , 3F
因為在寫for pc 的C程式時 好像沒碰過這樣的情況
03/25 15:03, 3F

03/25 15:05, , 4F
Helth 是資料型態,不是變數名稱
03/25 15:05, 4F

03/25 15:05, , 5F
就好像你不會寫 int = 3; 一樣
03/25 15:05, 5F

03/25 15:07, , 6F
真的是這樣 太久沒寫東西 連基本的都忘了 糟糕我...
03/25 15:07, 6F

03/25 15:07, , 7F
謝謝2位
03/25 15:07, 7F

03/25 15:12, , 8F
你的程式在PC上也會有一樣的問題的
03/25 15:12, 8F

03/25 15:14, , 9F
會忘記正常,因為C可以這樣 struct {int a; char c} xx;
03/25 15:14, 9F

03/25 15:14, , 10F
xx 放到 } 後面時,就變成「變數名稱」,而不是資料型態了
03/25 15:14, 10F
文章代碼(AID): #1DZ3oM_K (C_and_CPP)
文章代碼(AID): #1DZ3oM_K (C_and_CPP)