Locally declared labels (IBM extension)

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 diagram
Locally declared label syntax

              .-,----------.      
              V            |      
>>-__label__----identifier-+--;--------------------------------><

The declaration of local labels must precede any ordinary declarations and statements. The label declaration defines only the label name, so you must define the label itself in the usual way, with a name and a colon, within the statements of the statement expression.