参考资料:

  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的更多相关文章

  1. 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){ ...

  2. 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 ...

  3. [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 ...

  4. Namespace declaration statement has to be the very first statement in the script-去除bom头

    今天准备测试小程序的签名加密,但是刚引入官方的“加密数据解密算法”文件到项目里,然后为每个文件添加命名空间的时候,不管怎么加都报“Namespace declaration statement has ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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文 ...

随机推荐

  1. linux安装jdk以及tomcat

    一.卸载旧jdk 1.检测原OPENJDK版本 java -version 查看是否安装了jdk,并且是什么版本 2.进一步查看JDK信息 rpm -qa|grep java tzdata-java- ...

  2. new.target

    [new.target] The new.target property lets you detect whether a function or constructor was called us ...

  3. 字符串相似度算法(编辑距离Levenshtein Distance)的应用场景

    应用场景 DNA分析: 将DNA的一级序列如β-球蛋白基因的第一个外显子(Exon)转化为分子“结构图”,然后由所得“结构图”提取图的不变量,如分子连接性指数.以图的不变量作为自变量,再由相似度计算公 ...

  4. appium +ios 判断元素是否存在,排除visible=“false”的数据

    问题 想要判断name=xxx的元素是否存在,存在的话进行点击,结果页面并没有展示我要的元素时也提示找到了元素   原因 ios通过driver.find_element_by_name(“name值 ...

  5. Redis集群架构【转载】

    Redis 集群的 TCP 端口(Redis Cluster TCP ports) 每个 Redis 集群节点需要两个 TCP 连接打开.正常的 TCP 端口用来服务客户端,例如 6379,加 100 ...

  6. vue中使用全局函数

    方法一: 在mian.js中写入函数: Vue.prototype.bb = function () {        alert('OK'); } 然后在任何组件中都可以调用: this.bb() ...

  7. typedef void(*Func)(void)的简单用途

    typedef void(*Func)(void)的用途 用法的好处: 定义一个函数指针类型. 例子: 有三个类型相似或功能相似的函数: void TASK1(void) { printf(" ...

  8. ES6之Promise对象

    创建Promise对象 function getHtml(url) { return new Promise((resolve, reject) => { let xhr = new XMLHt ...

  9. java编程 求和

    用java编程,实现字符串强制类型转化成整数型,用到Integer.parseInt(),可以把字符串强制转换成整数 结果截图

  10. ajax中的contendType和dataType知识点梳理

    在ajax中有2个参数比较重要,之前一直没有搞清楚,下面我们开始梳理一下 1.contentType字段:这个字段的意思,ajax发送给后端的数据是什么类型 如果在ajax中不指定这个属性,则默认是u ...