赶上出口 [英] catching exit

查看:75
本文介绍了赶上出口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我正在尝试重用一段设计为

应用程序的代码。该代码包含退出调用。我想将

重新用作库。为此,我将''main''功能重命名为

''mymain'',但我对于我应该为''退出'做什么感到困惑。


AFAIK没有可移植的方式赶上出口。我唯一可以想到的是atexit,但这不起作用,因为''exit''仍然是

之后被调用。


我现在想的是我需要用

longjmp(env,val)替换所有的exit(val)。并使''env''全球化。


评论?


谢谢

-Mathieu

Hi there,

I am trying to reuse a piece of code that was designed as an
application. The code is covered with ''exit'' calls. I would like to
reuse it as a library. For that I renamed the ''main'' function into
''mymain'', but I am stuck as to what I should do for the ''exit''.

AFAIK there is no portable way to catch the exit. The only thing I
can think of is atexit, but that does not work since ''exit'' is still
called afterward.

What I am thinking now is that I need to replace all exit(val) with
longjmp(env, val). And make ''env'' global.

Comments ?

Thanks
-Mathieu

推荐答案

2008年8月13日21:33,CBFalconer写道:
On 13 Aug 2008 at 21:33, CBFalconer wrote:

mathieu写道:
mathieu wrote:

>我正在尝试重用一段设计为
应用程序的代码。该代码包含退出调用。我希望
将其重用为库。为此,我将''main''功能重命名为''mymain'',但我对于我应该为
''退出''做什么感到困惑。
>I am trying to reuse a piece of code that was designed as an
application. The code is covered with ''exit'' calls. I would like
to reuse it as a library. For that I renamed the ''main'' function
into ''mymain'', but I am stuck as to what I should do for the
''exit''.



只需将其调用exit即可。

Just leave it calling exit.



Brilliant。


提醒我永远不要使用你写的任何图书馆。


哦,是的,无论如何,即使没有这个

最新的白痴帖子,地狱也会先冻结。

Brilliant.

Remind me never to use any library you write.

Oh, yes, hell would have frozen over first anyway, even without this
latest idiotic post.


CBFalconer< ; cb ******** @ yahoo.comwrites:
CBFalconer <cb********@yahoo.comwrites:

mathieu写道:
mathieu wrote:

>我正在尝试重用一段设计为
应用程序的代码。该代码包含退出调用。我希望
将其重用为库。为此,我将''main''功能重命名为''mymain'',但我对于我应该为
''退出''做什么感到困惑。


我现在在想的是我需要用longjmp(env,val)替换所有出口(val)
。并使''env''全球化。
>I am trying to reuse a piece of code that was designed as an
application. The code is covered with ''exit'' calls. I would like
to reuse it as a library. For that I renamed the ''main'' function
into ''mymain'', but I am stuck as to what I should do for the
''exit''.

AFAIK there is no portable way to catch the exit. The only thing
I can think of is atexit, but that does not work since ''exit'' is
still called afterward.

What I am thinking now is that I need to replace all exit(val)
with longjmp(env, val). And make ''env'' global.



只需离开它就可以退出。结果如下:


7.20.4.3退出函数


Just leave it calling exit. The result is as follows:

7.20.4.3 The exit function



[C标准'对出口的描述功能剪断]


这是如何回答OP的问题的?


他有一个主程序;对exit的调用终止了程序。


他想把这个主程序变成一个更大的
程序中的函数。无论哪里有退出电话,他都想终止

功能,而不是整个(现在更大)的程序。


-

Keith Thompson(The_Other_Keith) ks***@mib.org < http://www.ghoti.net / ~kst>

诺基亚

我们必须做点什么。这是事情。因此,我们必须这样做。

- Antony Jay和Jonathan Lynn,Yes Minister

[C standard''s description of the exit function snipped]

And how does this answer the OP''s question?

He has a main program; a call to exit terminates the program.

He wants to turn this main program into a function within a larger
program. Wherever there''s a call to exit, he wants to terminate the
function, not the entire (now larger) program.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"


Keith Thompson写道:
Keith Thompson wrote:

CBFalconer< cb ******** @ yahoo.comwrites:
CBFalconer <cb********@yahoo.comwrites:

> mathieu写道:
>mathieu wrote:

>>我正在尝试重用一段设计为
应用程序的代码。该代码包含退出调用。我希望
将其重用为库。为此,我将''main''功能重命名为''mymain'',但我对于我应该为
''退出''做什么感到困惑。


我现在在想的是我需要用longjmp(env,val)替换所有出口(val)
。并使''env''全球化。
>>I am trying to reuse a piece of code that was designed as an
application. The code is covered with ''exit'' calls. I would like
to reuse it as a library. For that I renamed the ''main'' function
into ''mymain'', but I am stuck as to what I should do for the
''exit''.

AFAIK there is no portable way to catch the exit. The only thing
I can think of is atexit, but that does not work since ''exit'' is
still called afterward.

What I am thinking now is that I need to replace all exit(val)
with longjmp(env, val). And make ''env'' global.


请保持呼叫退出。结果如下:

7.20.4.3退出函数


Just leave it calling exit. The result is as follows:

7.20.4.3 The exit function



[C标准'对退出函数的描述剪断]


这是如何回答OP的问题的?


他有一个主程序;对exit的调用终止了程序。


他想把这个主程序变成一个更大的
程序中的函数。无论何时有退出电话,他都希望终止

功能,而不是整个(现在更大)的程序。

[C standard''s description of the exit function snipped]

And how does this answer the OP''s question?

He has a main program; a call to exit terminates the program.

He wants to turn this main program into a function within a larger
program. Wherever there''s a call to exit, he wants to terminate the
function, not the entire (now larger) program.



如果这是他想做的事情,那就是另一种情况。但

之前的效果是终止程序,这是什么退出




-

[mail]:Chuck F(cinefalconer at maineline dot net)

[page]:< http://cbfalconer.home.att.net>

尝试下载部分。

If that''s what he wants to do that is another case. But the
previous effect was to terminate the program, whch is what exit
does.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.


这篇关于赶上出口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆