Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


Share this Page URL
Help

Chapter 15: Statements > 15.5 Declaration statements - Pg. 405

372 void F() { ... if (done) goto exit; ... exit: ; } end example] CHAPTER 15: STATEMENTS 15.4 Labeled statements A labeled-statement permits a statement to be prefixed by a label. Labeled statements are per- mitted in blocks, but are not permitted as embedded statements. labeled-statement: identifier : statement A labeled statement declares a label with the name given by the identifier. The scope of a label is the whole block in which the label is declared, including any nested blocks. It is a compile-time error for two labels with the same name to have overlapping scopes. A label can be referenced from goto statements (§15.9.3) within the scope of the label. [Note: This means that goto statements can transfer control within blocks and out of blocks, but never into blocks. end note] Labels have their own declaration space and do not interfere with other identifiers. [Example: The example int F(int x) { if (x >= 0) goto x; x = -x; x: return x; } is valid and uses the name x as both a parameter and a label. end example] Execution of a labeled statement corresponds exactly to execution of the statement following the label. In addition to the reachability provided by normal flow of control, a labeled statement is reach- able if the label is referenced by a reachable goto statement, unless the goto statement is inside a try that includes a finally block whose end point is unreachable, and the labeled statement is outside the try. 15.5 Declaration statements A declaration-statement declares a local variable or constant. Declaration statements are per- mitted in blocks, but are not permitted as embedded statements. declaration-statement: local-variable-declaration ; local-constant-declaration ;