IBM extension

Locally declared labels

A locally declared label, or local label, is an identifier label that is declared at the beginning of a statement expression and for which the scope is the statement expression in which it is declared and defined. This language feature is an extension of C and C++ to facilitate handling programs developed with GNU C.

A local label can be used as the target of a goto statement, jumping to it from within the same block in which it was declared. This language extension is particularly useful for writing macros that contain nested loops, capitalizing on the difference between its statement scope and the function scope of an ordinary label.

Read syntax diagramSkip visual syntax diagramLocally declared label syntax
 
              .-,----------.
              V            |
>>-__label__----identifier-+--;--------------------------------><
 

In a statement expression, the declaration of a local label must appear immediately after the left parenthesis and left brace, and must precede any ordinary declarations and statements. The label is defined in the usual way, with a name and a colon, within the statements of the statement expression.

Related information

End of IBM extension