1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

msys2 ucrt64環境でquick_exitするための方法

Last updated at Posted at 2021-04-19

quick_exitとは

これ見てください

あるいは

をどうぞ

これまでのmsys2 mingwでは

使えません。msvcrtにはquick_exitが含まれていないからです。

msys2 ucrt64では

普通に使える・・・はずもなく、一工夫必要です。

以下のコードが最短でquick_exitを呼ぶ方法です。

extern "C" [[noreturn]] void quick_exit(int) noexcept;
int main()
{
        quick_exit(0);
}

つまり何かというと、/ucrt64/include/c++/10.2.0/cstdlibおよびそこから参照される/ucrt64/x86_64-w64-mingw32/include/stdlib.hにはまだquick_exitの宣言がありません。

でもucrt自体にはあるので、ならば標準ライブラリヘッダーなんか投げ捨てて自分で宣言を書けばいいわけですね!

~~・・・あとでバグレポ投げます。~~投げました

修正された

その後、mingwそのものの問題だったのでメーリングリストに投げ直していました。
https://sourceforge.net/p/mingw-w64/mailman/message/37265392/

すると

ぽんぽんと修正が投げられて承認されてmasterにpushされました

--- a/mingw-w64-headers/crt/stdlib.h
+++ b/mingw-w64-headers/crt/stdlib.h
@@ -387,6 +387,9 @@
 #define _CRT_TERMINATE_DEFINED
   void __cdecl __MINGW_NOTHROW exit(int _Code) __MINGW_ATTRIB_NORETURN;
   void __cdecl __MINGW_NOTHROW _exit(int _Code) __MINGW_ATTRIB_NORETURN;
+#ifdef _UCRT
+  void __cdecl __MINGW_NOTHROW quick_exit(int _Code) __MINGW_ATTRIB_NORETURN;
+#endif
 
 #if !defined __NO_ISOCEXT /* extern stub in static libmingwex.a */
   /* C99 function name */
@@ -420,6 +423,9 @@
 #endif
 
   int __cdecl atexit(void (__cdecl *)(void));
+#ifdef _UCRT
+  int __cdecl at_quick_exit(void (__cdecl *)(void));
+#endif
 #ifndef _CRT_ATOF_DEFINED
 #define _CRT_ATOF_DEFINED
   double __cdecl atof(const char *_String);

そして

https://sourceforge.net/p/mingw-w64/mailman/message/37266669/

This has been fixed on master now:

と言ってくるLiu Haoさんめっちゃかっこいい。

はやくmsys2に降ってこないかなぁ・・・。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?