6.8.6.1 The goto statement

Previous Table of Contents

1773 The identifier in a goto statement shall name a label located somewhere in the enclosing function.

1774 A goto statement shall not jump from outside the scope of an identifier having a variably modified type to inside the scope of that identifier.

1775 A goto statement causes an unconditional jump to the statement prefixed by the named label in the enclosing function.

1776 EXAMPLE 1 It is sometimes convenient to jump into the middle of a complicated set of statements. The following outline presents one possible approach to a problem based on these three assumptions:

  1. The general initialization code accesses objects only visible to the current function.

  2. The general initialization code is too large to warrant duplication.

  3. The code to determine the next operation is at the head of the loop. (To allow it to be reached by continue statements, for example.)


        /* ... */
        goto first_time;
        for (;;) {
                // determine next operation
                /* ... */
                if (need to reinitialize) {
                        // reinitialize-only code
                        /* ... */
                first_time:
                        // general initialization code
                        /* ... */
                        continue;
                }
                // handle other operations
                /* ... */
        }

1777 EXAMPLE 2

A goto statement is not allowed to jump past any declarations of objects with variably modified types. A jump within the scope, however, is permitted.


        goto lab3;                        // invalid: going INTO scope of VLA.
        {
                double a[n];
                a[j] = 4.4;
        lab3:
                a[j] = 3.3;
                goto lab4;                // valid: going WITHIN scope of VLA.
                a[j] = 5.5;
        lab4:
                a[j] = 6.6;
        }
        goto lab4;                        // invalid: going INTO scope of VLA.

Next

Created at: 2005-06-29 02:19:03 The text from WG14/N1124 is copyright © ISO