参考资料:

  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. 23种经典设计模式UML类图汇总

    在这里23种经典设计模式UML类图汇总       创建型模式 1.FACTORY—追MM少不了请吃饭了,麦当劳的鸡翅和肯德基的鸡翅都是MM爱吃的东西,虽然口味有所不同,但不管你带MM去麦当劳或肯德基 ...

  2. MFC笔记1

    1.在对话框文档中定义两个定时器,每间隔5秒弹出一个消息框提示“定时器1”,每隔5秒弹出一个消息框提示“定时器2” UINT ID_TIMER1 = 1 , ID_TIMER2 = 2;   //设置 ...

  3. 2018面向对象程序设计(Java)第11周学习指导及要求

    2018面向对象程序设计(Java)第11周学习指导及要求 (2018.11.8-2018.11.11)   学习目标 (1) 掌握Vetor.Stack.Hashtable三个类的用途及常用API: ...

  4. hadoop zookeeper高可用

    原文地址: https://blog.csdn.net/dingchenxixi/article/details/51131493 core-site.xml yarn-site.xml

  5. 制作u盘kali系统启动盘

    准备好一个容量大于8G的u盘,和kali系统的镜像文件. 下载universal-usb-install软件,打开设置如下,create等待几分钟. 下载minitool分区工具,插入u盘,打开min ...

  6. 如何修改Eclipse的 workspace目录

    Eclipse是一款很强的Java IDE, eclipse ide for eclipse committers 这里的committers 就是投稿者与执行者的意思,也就是说这个eclipse是为 ...

  7. c++中的类(class)-----笔记(类简介)

    1, class 和 struct 都可以定义一个类,区别是两者在所支持的 默认信息隐藏方式不同:c++ 中默认为 private 类型,而 struct 中默认为 public 类型. 2,类的私有 ...

  8. es快照定时备份脚本

    #!/bin/bashdata1=`date "+%Y%m%d"`data2="http://0.0.0.0:9200/_snapshot/my_backup/snaps ...

  9. BP神经网络学习

    人工神经元模型     S型函数(Sigmoid) 双极S型函数 神经网络可以分为哪些? 按照连接方式,可以分为:前向神经网络 vs. 反馈(递归)神经网络 按照学习方式,可以分为:有导师学习神经网络 ...

  10. PAT1020 (已知中序,后序遍历转前序遍历)

    已知后序与中序输出前序(先序):后序:3, 4, 2, 6, 5, 1(左右根)中序:3, 2, 4, 1, 6, 5(左根右) 已知一棵二叉树,输出前,中,后时我们采用递归的方式.同样也应该利用递归 ...