a label can only be part of statement and a declaratioin is not a statement
参考资料:
https://stackoverflow.com/questions/18496282/why-do-i-get-a-label-can-only-be-part-of-a-statement-and-a-declaration-is-not-a
问题背景:
写了一段code,如下:
#include<stdio.h> int main()
{
int a;switch (a) {
case :
break;
case :
int aa;
break;
case :
break;
default:
break;
} return ;
}
如上所示code编译时候会报错,错误提示“a label can only be part of statement and a declaratioin is not a statement”。
问题原因:
引用一段话解释为“Prior to C99, all declarations had to precede all statements within a block, so it wouldn't have made sense to have a label on a declaration. C99 relaxed that restriction, permitting declarations and statement to be mixed within a block, but the syntax of a labeled-statement was not changed. – Keith Thompson”。
翻译过来就是,C99之前,在一代码块中所有的定义都必须在声明之前,所以,一个标签在定义之前是没有意义的。C99放宽了这个限制,允许代码块中混合定义、声明,但这这个标签不能在定义之前的限制没有改变。
解决方法:
#include<stdio.h> int main()
{
int a;
switch (a) {
case :
break;
case :; //加一个空的‘;’,标示空声明
int aa;
break;
case :
break;
default:
break;
} return ;
}
#include<stdio.h> int main()
{
int a;
int aa; //定义放到 switch 之前
switch (a) {
case :
break;
case :
break;
case :
break;
default:
break;
} return ;
}
a label can only be part of statement and a declaratioin is not a statement的更多相关文章
- error: a label can only be part of a statement and a declaration is not a statement
GCC: error: a label can only be part of a statement and a declaration is not a statement switch(a){ ...
- c 编译异常 switch 之a label can only be part of a statement and a declaration is not a statement
client.c:996: error: a label can only be part of a statement and a declaration is not a statement sw ...
- [MySQL复制异常]'Cannot execute statement: impossible to write to binary log since statement is in row format and BINLOG_FORMAT = STATEMENT.'
MySQL复制错误]Last_Errno: 1666 Last_Error: Error executing row event: 'Cannot execute statement: imposs ...
- Namespace declaration statement has to be the very first statement in the script-去除bom头
今天准备测试小程序的签名加密,但是刚引入官方的“加密数据解密算法”文件到项目里,然后为每个文件添加命名空间的时候,不管怎么加都报“Namespace declaration statement has ...
- ERROR 1666 (HY000): Cannot execute statement: impossible to write to binary log since statement is in row format and BINLOG_FORMAT = STATEMENT.
centos7.5 binlog恢复数据失败 问题: mysql> \. /tmp/inc.sql ERROR 1050 (42S01): Table 'new_1' already exist ...
- PHP错误:Namespace declaration statement has to be the very first statement in the script
PHP错误:Namespace declaration statement has to be the very first statement in the script 原因:意思就是“names ...
- MySQL:Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT...
1:错误日志大量错误 150602 14:40:02 [Warning] Unsafe statement written to the binary log using statement form ...
- Namespace declaration statement has to be the very first statement or after any declare call in the script
0x00缘起 代码部署在windows上,出现了一个bug,临时用记事本打开修改了一下,于是出现了500错误 0x01排错 查看log,提示如下 "Namespace declaration ...
- Namespace declaration statement has to be the very first statement in the script
php 中 Namespace declaration statement has to be the very first statement in the script 错误解决方法: 在PHP文 ...
随机推荐
- JAVA语言 第四周
oh my god! 说实话,上周的目标没有完成. 这一周过的太随便了,比刚放假时候的热情减少的太多了. 具体干了啥,就不说了吧.好像什么完整的事都没有干~~~~~ 不过一直在完善代码,已经能实现部分 ...
- 2017面向对象程序设计(JAVA)课程总结
以下就课程结束之后的问题进行简单小结:1. 关于课程教学方法 课程在部分章节的学习中采用了翻转课堂教学,目的是促进同学们借助方便获取的线上线下学习资源进行课前自学,以便于老师留出课堂时间进 ...
- numpy 矩阵变换transpose和swapaxes
1.transpose 交换 arr = np.random.arange().reshape((,,)) # ** = 则 arr_shape = arr.shape # ,, 则 arr 索引 # ...
- sqlite3调试
[sqlite3调试] 1.adb shell 激活模拟器shell. 2.cd /data/data/com.xxx.xxx/databases 进入app 数据库目录. 3.ls 查看有哪些数据库 ...
- linux按键映射
.Xmodmap keycode = Mode_switch keysym k = k K Left keysym j = j J Down keysym l = l L Right keysym h ...
- Android Studio 插件-Android Styler 的使用 (转)
作用:把 xml文件 转为 style 截图保留 使用方法 使用方法:选中xml代码 按下 Ctrl+Shift+D 转自:http://blog.csdn.net/zxwd2015/article/ ...
- sqlserver 当前时间减去30天
参考 https://zhidao.baidu.com/question/750666819064717772.html select dateadd(dd,-30,getdate()) from 表 ...
- k8s volume 基本类型分类
volume 类型 静态volume emptyDir 临时空目录, 用途,pod内多用户同享一个目录.与POD的生命周期一至,POD创建时创建,删除时删除. Hostpath 宿主机1:1映射,用途 ...
- Linux服务器安装配置Nginx服务器
Nginx("engine x")是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能的 Web和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务 ...
- javaWEB登录ajax传值
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...