Re: [learn-linux-c-cpp] learning-linux-c-cpp@googlegroups.com 的摘要 - “1 个主题”有 1 个帖子

9 views
Skip to first unread message

Green Lake

unread,
Dec 10, 2013, 4:08:04 AM12/10/13
to learning-l...@googlegroups.com
想要的就是个像break一样的机制,在||里就可以跳到我想去的地方,又不用goto。
setjmp和longjmp的方法看起来不错。


在 2013年11月19日下午11:42, <learning-l...@googlegroups.com>写道:

网上论坛: http://groups.google.com/group/learning-linux-c-cpp/topics

    Jun Li <junl...@gmail.com> Nov 19 09:26AM -0500  

    "请问有没有办法写成这样:
    init_x() || init_y() || init_z() || myreturn() ;"
     
    你用setjmp longjmp 倒是可以恢复到之前的call stack,
     
    void main()
    {
    jmp_buf env;
    if (setjmp(env))
    {
    return;
    }
    init_x() || init_y() || my_return(&env);
    }
     
    int my_return(jmp_buf* env)
    {
    longjmp(*env, 1);
    return 0; //not executed
    }
     
    这个法子其实就是捕获异常了,目测就算嵌入汇编也得是要保存上下文才行吧, 其实还不如 if else
     
     
     
    2013/11/14 guokr321 <guok...@163.com>
     

     

--
您收到此邮件是因为您订阅了 Google 网上论坛的“Linux C/C++/系统编程 一站式学习”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到 learning-linux-c...@googlegroups.com
要查看更多选项,请访问 https://groups.google.com/groups/opt_out。

Reply all
Reply to author
Forward
0 new messages