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

来源:互联网 发布:配音软件 编辑:程序博客网 时间:2024/05/21 19:34

代码:

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中是不允许的。
原创粉丝点击