不需要函数间跳转,函数内跳转就可以。
#include <iostream>
#include <stack>
using namespace std;
int main() {
unsigned int label1,label2;
stack<unsigned int> stk;
stk.push(label1);
stk.push(label2);
while(!stk.empty()) {
unsigned int to=stk.top();
stk.pop();
goto to;
}
resume:
int i=0;
if(++i==5) goto exit;
label1:
cout << " This is label1" << endl;
goto resume;
label2:
cout << " This is label2" << endl;
goto resume;
exit:
return 0;
}
$ g++ -g goto.cpp
goto.cpp: In function 'int main()':
goto.cpp:26:14: error: label 'to' used but not defined
goto to;
^~
【 在 flw 的大作中提到: 】
: man longjmp
: man setjmp
:
--
修改:luchu FROM 119.251.19.*
FROM 119.251.19.*