Could not be a label in the middle stream declaration in C?

So this is in C99:

label:
  int ret = function(of, stuff);

gives a compile-time error, whereas this:

label:
  ;
  int ret = function(of, stuff);

works great.

Is this a compiler error? Or is it a mistake in defining the standard C? Or, if it's part of the C99 standard, maybe someone will stand up for the C standard to argue that it makes sense?

+4
source share
2 answers

Labels that are defined in N1256 . 6.8.1 The statements indicated may contain only instructions.

 Syntax  
1      labeled-statement:  
           identifier : statement  
           case constant-expression : statement  
           default : statement

int ret = function(of, stuff); is an announcement that is defined in N1256 6.7 Announcements and is not an expression.

Statements are defined below in N1256 6.8. Expressions and blocks:

 Syntax
1      statement:
           labeled-statement
           compound-statement
           expression-statement
           selection-statement
           iteration-statement
           jump-statement

compound-statement - , 0 , {}.

expression-statement - , N1256 6.5. , , i++;. N1256 6.5.17 Comma-.

selection-statement - if switch.

iteration-statement - while, do-while for.

jump-statement goto, continue, break return.

, , .

+7

, - , ( , ), , , . , .

, , , .

+4

Source: https://habr.com/ru/post/1651850/


All Articles