6.8.6.1 The goto statement

Previous Table of Contents "New C Standard" commentary

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

1788 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.

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

1790 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
                /* ... */
        }

1791 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: 2008-01-30 02:39:44 The text from WG14/N1256 is copyright © ISO