参考资料:

  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. Elasticsearch搜索异常-------org.elasticsearch.common.io.stream.NotSerializableExceptionWrapper: parse_exception

    异常问题: Caused by: org.elasticsearch.index.query.QueryShardException: Failed to parse query [LOL: Uzi和 ...

  2. Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.0.2:resources 在我的myeclipse中新建maven工程总出现这个问题

    只需在下图中更改代码 更改后是这样的: <plugin> <groupId>org.apache.maven.plugins</groupId> <artif ...

  3. SpringBoot 热启动

    在开发过程中,当写完一个功能我们需要运行应用程序测试,可能这个小功能中存在多个小bug,我们需要改正后重启服务器,这无形之中拖慢了开发的速度增加了开发时间,SpringBoot提供了spring-bo ...

  4. KNN算法应用

    import numpy as np# 运算符模块,这里主要用来排序 import operator import matplotlib.pylab as plt def create_dataset ...

  5. Java-分治算法

    一.分治算法的原理 分治算法就是将一个规模为N的问题分解成K个规模较小的子问题,这些子问题相互独立且与原问题性质相同,求出子问题的解,就可以得出原问题的解 二.分治算法的伪代码实现 合并算法Merge ...

  6. require模块化载入

    1,模块化require的载入步骤 1,一个总文件夹,,里面三个子文件夹 ,, 分别是 2,common 里面是放一些公共方法和自己封装的方法     js里面是放自己的业务逻辑js文件和一些模块化的 ...

  7. elasticsearch查询语句总结

    query 和  filter 的区别请看:https://www.cnblogs.com/bainianminguo/articles/10396956.html Filter DSL term 过 ...

  8. Windows 64 位 mysql 5.7.20 安装教程

    mysql 5.7以上版本包解压中没有data目录和my-default.ini和my.ini文件以及服务无法启动的解决办法以及修改初始密码的方法 mysql官网下载地址:https://dev.my ...

  9. TableView中Label自适应高度

    //Xcode6.3以后label自适应需要添加两个属性 _tableView.rowHeight = UITableViewAutomaticDimension; //给予预计行高 _tableVi ...

  10. call指令

    CPU执行call指令时,进行两步操作: 将当前的IP或CS和IP压入栈中; 转移. call指令不能实现短转移,除此之外,call指令实现转移的方法和jmp指令的原理相同. 1)依据位移进行转移的c ...