• 静态变量在 main 函数前执行初始化
  • on_exit 注册的函数在 main 执行后再执行
void f(int state, void* msg){
    cout << "after main exit.\n";
    cout << "state: " << state << "\t message: " << (char*)msg << endl;
}
int main()
{
    cout << "Hello World\n";
    on_exit(f, (char*)"this is message");
    cout << "end of main.\n";
    return 0;
}

输出:

Hello World
end of main.
after main exit.
state: 0	 message: this is message