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

前端 未结 3 1396
耶瑟儿~
耶瑟儿~ 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:53

    You can test whether stack unwinding occurs, with some simple code:

    #include 
    #include 
    using namespace std;
    
    struct A {
        ~A() { cerr << "unwound" << endl; }
    };
    
    int main() {
        A a;
        while(1) {
            Sleep(1000);
        }
    }
    

    Whether it occurs not should be implementation dependant, depending on how the runtime handles the Ctrl-C. In my experience, it does not take place.

提交回复
热议问题