Using Goto function across different functions

前端 未结 4 2103
心在旅途
心在旅途 2020-12-18 20:58

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

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

    void function()
    {
             


        
4条回答
  •  孤城傲影
    2020-12-18 21:24

    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.

提交回复
热议问题