在C中流声明中不能有标签?

Mar*_*ler 4 c standards goto c99

所以这在C99:

label:
  int ret = function(of, stuff);
Run Code Online (Sandbox Code Playgroud)

给出了一个编译时错误,而这个:

label:
  ;
  int ret = function(of, stuff);
Run Code Online (Sandbox Code Playgroud)

工作得很好.

这是编译器错误吗?或者这是C标准定义中的错误?或者,如果这是C99标准的一部分,也许有人会捍卫C标准,声称这是完全合理的?

Mik*_*CAT 9

标签在N1256 6.8.1标记语句中定义,只能包含语句.

 Syntax  
1      labeled-statement:  
           identifier : statement  
           case constant-expression : statement  
           default : statement
Run Code Online (Sandbox Code Playgroud)

int ret = function(of, stuff);是一份声明,在N1256 6.7声明中定义,不是声明.

报告定义见下文N1256 6.8声明和块:

 Syntax
1      statement:
           labeled-statement
           compound-statement
           expression-statement
           selection-statement
           iteration-statement
           jump-statement
Run Code Online (Sandbox Code Playgroud)

compound-statement是所谓的,它是由0或更多的声明和语句包围的{}.

expression-statement是N1256 6.5表达式中定义的零或一个表达式,后跟分号i++;.语法中的表达式在N1256 6.5.17逗号运算符中定义.

selection-statementifswitch声明.

iteration-statementwhile,do-whilefor声明.

jump-statementgoto,continue,breakreturn声明.

如您所见,声明不是声明,因此您不能将标签放在声明中.