What exactly is the effect of Ctrl-C on C++ Win32 console applications?

前端 未结 3 1297
耶瑟儿~
耶瑟儿~ 2021-01-17 10:57
  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?
3条回答
  •  情话喂你
    2021-01-17 11:51

    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.

提交回复
热议问题