Using Goto function across different functions

Bhushanam Bhargav picture Bhushanam Bhargav · Jun 28, 2013 · Viewed 23.7k times · Source

How can I use goto function across different functions .For ex ,

    main()
    {
      ....
      REACH:
      ......
    }

    void function()
    {
    goto REACH ;
    }

How to implement such usage ?

Answer

Captain Obvlious picture Captain Obvlious · Jun 28, 2013

You can't in Standard C++. From $6.6.4/1 of the C++ Language Standard

The goto statement unconditionally transfers control to the statement labeled by the identifier. The identifier shall be a label (6.1) located in the current function.

...or in Standard C. From $6.8.6.1/1 of the C Language Standard

The identifier in a goto statement shall name a label located somewhere in the enclosing function. 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.