奇怪的 error C2143: syntax error : missing ';' before 'type'

代碼:

int x = 6;

if (bFlag)

   x = 8;

int y = 6;

VS2005編譯報錯: error C2143: syntax error : missing ';' before 'type'

報錯位置: int y = 6;

去掉  if(bFlag)

   x = 8;

編譯成功,這不應該啊,沒有語法錯誤。

最後去掉 int y = 6;中的  int編譯通過。

給出的解釋:

In Microsoft C, compiler errors C2143 and C2144 are defined as follows:

    C2143: syntax error : missing 'token1' before 'token2'
    C2144: syntax error : missing 'token' before type 'type'

 

You may receive this error message if your program places executable code before a data declaration, an acceptable practice in Kernighan-and-Ritchie C. This practice has been outlawed in later versions of the ANSI drafts.

This error message will normally occur if a required closing curly brace (}), right parenthesis [)], or semicolon (;) is missing. 

在 ANSI C或者C++中,在可執行代碼中隨時定義變量是允許的,但是在K&R C中是不允許的。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章