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文 ...
随机推荐
- 构建缓存gradle
结合Kotlin使用Gradle build cache 宛丘之上兮 关注 2018.03.11 00:21* 字数 1177 阅读 505评论 5喜欢 4 在2017年4月,Gradle发布了bui ...
- 大型运输行业实战_day11_2_事务理论与实际生产配置事务管理
1.什么是事务(Transaction:tx) 数据库的某些需要分步完成,看做是一个整体(独立的工作单元),不能分割,要么整体成功,要么整体生效.“一荣俱荣,一损俱损”,最能体现事务的思想.案例:银行 ...
- openssl数字证书常见格式 协议
证书主要的文件类型和协议有: PEM.DER.PFX.JKS.KDB.CER.KEY.CSR.CRT.CRL .OCSP.SCEP等. PEM – Openssl使用 PEM(Privacy Enha ...
- React中innerHTML的坑
[React中innerHTML的坑] 通过React Ref机制返回的对象,是一个阉割的DOM对象,并非原始DOM对象.比如,这个阉割版的DOM对象没有innerHTML对象. <button ...
- reids 基本操作
redis 基本操作 1. 什么是Redis Redis是由意大利人Salvatore Sanfilippo(网名:antirez)开发的一款内存高速缓存数据库.Redis全称为:Remote Dic ...
- PHP ActiveRecord demo栗子中 关于类名 的问题
问题: ActiveRecord如何将单个类名与表名相关联? 我昨天才发现了ActiveRecord,很奇妙的php数据库框架. 但是,我仍然对以下工作感到困惑: 1.下面这个Person Model ...
- jpa orderby
return criteriaQuery.where(in).orderBy(new OrderImpl(root.get("field1"))).getRestriction() ...
- l2-22(重排链表)
题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805057860517888 题意:给定链表L1->L2- ...
- ceph 维护之 osd节点添加
一.目标 添加一台新osd 节点,主机名ceph6 到 ceph 集群.public IP:10.6.32.25 cluster_network :10.6.33.25 二.基础环境配置 1 ...
- CentOS 下lvm 磁盘扩容
打算给系统装一个oracle,发现磁盘空间不足.在安装系统的时候我选择的是自动分区,系统就会自动以LVM的方式分区.为了保证系统后期的可用性,建议所有新系统安装都采用LVM,之后生产上的设备我也打算这 ...