标号语句 与 变量定义

标号语句有:goto、case ,用 vc 6.0  goto 和case里头定义变量都提示错误,vc 在函数执行语句开始后就不能再定义或声明变量了。(dev c++未测试)

以下是官方解释:见 http://en.cppreference.com/w/c/language

Explanation
The goto statement causes an unconditional jump (transfer of control) to the statement prefixed by the named label (which must appear in the same function as the goto statement), except when this jump would enter the scope of a variable-length array or another variably-modified type. (since C99)
A label is an identifier followed by a colon (:) and a statement. Labels are the only identifiers that have function scope: they can be used (in a goto statement) anywhere in the same function in which they appear. There may be multiple labels before any statement.
Entering the scope of a non-variably modified variable is permitted:
goto lab1; // OK: going into the scope of a regular variable
    int n = 5;
lab1:; // Note, n is uninitialized, as if declared by int n; n值未知
 
//   goto lab2;   // Error: going into the scope of two VM types
     double a[n]; // a VLA
     int (*p)[n]; // a VM pointer
lab2:

OK: going into the scope of a regular variable 和 Note, n is uninitialized, as if declared by int n; 这两句话的意思应该是goto对定义的普通变量,但只是跳过了初始化,没有跳过声明,所以声明还是会执行;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值