您的位置:首页 > 其它

标号语句 与 变量定义

2018-02-22 16:58 225 查看
标号语句有: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
; // a VLA
     int (*p)
; // a VM pointer
lab2:

OK: going into the scope of a regular variable 和 Note, n is uninitialized, as if declared by int n; 这两句话的意思应该是goto对定义的普通变量,但只是跳过了初始化,没有跳过声明,所以声明还是会执行;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐