Ctrl-C对C ++ Win32控制台应用程序有什么影响? [英] What exactly is the effect of Ctrl-C on C++ Win32 console applications?

查看:87
本文介绍了Ctrl-C对C ++ Win32控制台应用程序有什么影响?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • 是否可以以某种方式处理此事件?

  • 在堆叠展开和静态/全局对象的释放方面会发生什么? >


    解决方案

    编辑:SIGINT,而不是SIGTERM。并且Assaf报告没有对象被破坏(至少在Windows上)的未处理SIGINT。



    系统发送SIGINT。这个概念适用于所有C实现(有一些差异)。要处理它,你调用signal,指定一个信号处理程序。有关信号函数的文档,请参见打开组 MSDN



    第二个问题有点棘手,可能取决于实现。最好的办法是处理信号,允许您手动使用 delete exit()。 >

    1. Is it possible to handle this event in some way?
    2. What happens in terms of stack unwinding and deallocation of static/global objects?

    解决方案

    EDIT: SIGINT, not SIGTERM. And Assaf reports that no objects are destroyed (at least on Windows) for unhanded SIGINT.

    The system sends a SIGINT. This concept applies (with some variance) for all C implementations. To handle it, you call signal, specifying a signal handler. See the documentation on the signal function at Open Group and MSDN.

    The second question is a little trickier, and may depend on implementation. The best bet is to handle the signal, which allows you to use delete and exit() manually.

    这篇关于Ctrl-C对C ++ Win32控制台应用程序有什么影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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