Enable __USE_MINGW_ANSI_STDIO for C99 and C++11 when not using UCRT
C99 and C++11 standards requires printf ll modifier for long long type but
it does not work in WinXP system msvcrt.dll. It requires at least library
msvcr80.dll.
So when gcc is invoked with --std=c99 (or new) or --std=c++11 (or new) ansi
stdio macro needs to be enabled for printf ll modifier support.
It is already enabled for _ISOC99_SOURCE but apparently new version of gcc
set only __STDC_VERSION__ and __cplusplus numeric macros to version of
C/C++ standard. So enable __USE_MINGW_ANSI_STDIO based on them.
Also GNU version of printf supports ll modifier in C mode, so enable
__USE_MINGW_ANSI_STDIO also for _GNU_SOURCE C mode (not only C++).
Signed-off-by: Liu Hao <lh_mouse@126.com>
diff --git a/mingw-w64-headers/crt/_mingw.h.in b/mingw-w64-headers/crt/_mingw.h.in
index 2be2d18..460d932 100644
--- a/mingw-w64-headers/crt/_mingw.h.in
+++ b/mingw-w64-headers/crt/_mingw.h.in
@@ -418,15 +418,16 @@
#endif
/* We are activating __USE_MINGW_ANSI_STDIO for various define indicators.
- Note that we enable it also for _GNU_SOURCE in C++, but not for C case. */
+ * printf ll modifier (unsupported by msvcrt.dll) is required by C99 and C++11 standards. */
#if (defined (_POSIX) || defined (_POSIX_SOURCE) || defined (_POSIX_C_SOURCE) \
|| defined (_ISOC99_SOURCE) \
+ || (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L && !defined(_UCRT)) \
+ || (defined (__cplusplus) && __cplusplus >= 201103L && !defined(_UCRT)) \
|| defined (_XOPEN_SOURCE) || defined (_XOPEN_SOURCE_EXTENDED) \
- || (defined (_GNU_SOURCE) && defined (__cplusplus)) \
+ || defined (_GNU_SOURCE) \
|| defined (_SVID_SOURCE)) \
&& !defined(__USE_MINGW_ANSI_STDIO)
-/* Enable __USE_MINGW_ANSI_STDIO if _POSIX defined
- * and If user did _not_ specify it explicitly... */
+/* Enable __USE_MINGW_ANSI_STDIO if user did _not_ specify it explicitly... */
# define __USE_MINGW_ANSI_STDIO 1
#endif