参考资料:

  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. phpexcel如何读取带公式的excel文件得到值呢?

    如果某个cell使用到了公式通过getValue()获取的是公式本身而通过getCalculatedValue()会有对象     getFormattedValue()获取到的是公式计算后的值

  2. Django 基础教程中的Django表单

    在 urls.py 中对应写上这个函数,教程中给的Django 1.7x以下的,我的时2.0.7,应该为 from django.contrib import admin from django.ur ...

  3. nltk的使用

    1. 命令行; import nltk nltk.download() #下载相关模型等,...

  4. javascript 执行环境,作用域、作用域链、闭包

    1.执行环境 执行环境是JavaScript中国最为重要的一个概念.执行环境定义了变量或函数有权访问的其他数据,决定了他们各自的行为.每个执行环境都有一个与之关联的变量对象,环境中定义的所有变量和函数 ...

  5. linux按键映射

    .Xmodmap keycode = Mode_switch keysym k = k K Left keysym j = j J Down keysym l = l L Right keysym h ...

  6. Oracle怎么修改字段类型

    转载:https://www.2cto.com/database/201710/689523.html 有一个表名为tb,字段段名为name,数据类型nchar(20). 1.假设字段数据为空,则不管 ...

  7. tcp/ip通信第5期之服务器端程序

    /* 此程序是tcp/ip通信服务器端程序,测试运行在redhat5上 重构readline函数,解决粘包问题——利用“\n”识别一个消息边界 */ #include<stdio.h> # ...

  8. Rxjs之创建操作符(Angular环境)

    一 of操作符 import { Component, OnInit } from '@angular/core'; import { of } from 'rxjs/observable/of'; ...

  9. linux 日常实用操作

    [Tab]接在一串指令的第一个字的后面,为[命令补全] [Tab]接在一串命令的第二个字以后时,则为[文件补全] 若安装bash-completion 软件,则在某些指令后面使用[Tab]按键时,可以 ...

  10. shell中颜色的设置

    linux启动后环境变量加载的顺序为:etc/profile → /etc/profile.d/*.sh → ~/.bash_profile → ~/.bashrc → [/etc/bashrc] 想 ...