标号语句 与 变量定义
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对定义的普通变量,但只是跳过了初始化,没有跳过声明,所以声明还是会执行;
以下是官方解释:见 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对定义的普通变量,但只是跳过了初始化,没有跳过声明,所以声明还是会执行;
相关文章推荐
- case语句中的变量定义
- 说明定义游标cursor时的select语句里可以用变量
- case语句中定义变量要加括号
- sql语句变量定义和样例
- C语言switch case语句中定义变量问题
- “System.Data.DataSet”不包含“GetEnumerator”的公共定义,因此 foreach 语句不能作用于“System.Data.DataSet”类型的变量
- 在case语句中定义变量的问题
- C语言switch case语句中定义变量问题
- vc6中for语句定义的变量的作用域超出for循环的解决办法
- 定义一个结构体变量(包括年、月、日),编写程序,要求输入年月日,程序能够计算并输出改日是本年中的第几天。注意闰年问题。(switch语句)
- C语言switch case语句中定义变量问题
- vb下的with语句定义BITMAPINFO类型的变量
- 主变量 用于动态 SQL 语句、视图定义或者触发器定义中
- VS插件开发——格式化变量定义语句块
- 关于怎么在php中定义的sql语句中使用变量
- C语言switch case语句中定义变量问题
- Atitit. 构造ast 语法树的总结attilax oao 1. Ast结构树形12. ast view (自是个160k的jar )22.1. 多条语句ast结构22.2. 变量定义 int b,c; 的ast结构22.3. 方法调用meth1(a=1,b=2,c=3); 的ast结构23. 误解的问题33.1. 语法书子能是个二叉树,实际上多叉树越好..33.2. 非要不个ast放到个s
- 一个函数内的复合语句中定义的变量…
- python基础----函数的定义和调用、return语句、变量作用域、传参、函数嵌套、函数对象、闭包、递归函数
- vc6.0中for语句变量重定义问题解决办法