atexit, _onexit, _onexit_m について
atexit, _onexit, _onexit_m の違いについてのメモ。
atexit 関数
_onexit 関数
_onexit_m 関数
- C++/CLI 用の _onexit 関数。
- 関数のプロトタイプ: int (__clrcall *)(void)
使い分けの例
#include <cstdlib> #ifdef _MSC_VER #include <process.h> // VC++ を使っている場合のみインクルード #endif // 終了時にコールバックする関数 void foo() { ... } #ifdef _MSC_VER // 戻り値を int にする (キャストして誤魔化しても動くけど、なんか不安なので) int foo_wrapper() { foo(); return 0; } #endif // atexit, _onexit, _onexit_m を呼び出す関数 void bar() { #if defined(_MSC_VER) && defined(__cplusplus_cli) _onexit_m(foo_wrapper); // C++/CLI with VC++ #elif defined(_MSC_VER) _onexit(foo_wrapper); // C++ with VC++ #else atexit(foo); // ANSI 準拠 #endif }