warning iso c90 forbids mixed declarations and code

Reference : http://forum.codecall.net/c-c/14212-iso-c90-forbids-mixed-declarations-code.html


  最近寫Linux Device Driver時碰到了warning: iso c90 forbids mixed declarations and code
雖然這只是一個Warning而已,但是在編譯時跑一堆出來就看起來不舒服,所以就上網
去找問題是什麼,最後找到的解答是:


#1. C90 Doesn't let you declare a variable inside a code block, except right at the very beginning.
  C90不讓你定義變數在Code block之間,所以你的變數必須在code的一開始就要定義好了

不合法的範例:

Code:
main(){
int oldtime;
oldtime = tickcount();
int nowtime;
nowtime = tickcount();
}

合法的範例:

Code:
main(){
int oldtime;
int newtime;
oldtime = tickcount();
newtime = tickcount();
}

留言

熱門文章