奇怪的 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中是不允许的。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值