From f7d9426f8e3f56a2384a4ced1c2f051cb7699383 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Thu, 1 Nov 2018 23:25:47 +0000 Subject: [PATCH] Add a way to use %zd on MinGW(-w64) This is suggested here: https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/ Compared to using __USE_MINGW_ANSI_STDIO, this prevents those annoying warning about "unsupported" format specifiers. --- stb_leakcheck.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/stb_leakcheck.h b/stb_leakcheck.h index d68e109..ad0938b 100644 --- a/stb_leakcheck.h +++ b/stb_leakcheck.h @@ -91,19 +91,23 @@ void *stb_leakcheck_realloc(void *ptr, size_t sz, const char *file, int line) static void stblkck_internal_print(const char *reason, const char *file, int line, size_t size, void *ptr) { -#if (defined(_MSC_VER) && _MSC_VER < 1900) /* 1900=VS 2015 */ || defined(__MINGW32__) +#if defined(_MSC_VER) && _MSC_VER < 1900 // 1900=VS 2015 // Compilers that use the old MS C runtime library don't have %zd // and the older ones don't even have %lld either... however, the old compilers // without "long long" don't support 64-bit targets either, so here's the // compromise: - #if (defined(_MSC_VER) && _MSC_VER < 1400) /* before VS 2005 */ || defined(__MINGW32__) + #if defined(_MSC_VER) && _MSC_VER < 1400 // before VS 2005 printf("%-6s: %s (%4d): %8d bytes at %p\n", reason, file, line, (int)size, ptr); #else printf("%-6s: %s (%4d): %8lld bytes at %p\n", reason, file, line, (long long)size, ptr); #endif #else // Assume we have %zd on other targets. - printf("%-6s: %s (%4d): %zd bytes at %p\n", reason, file, line, size, ptr); + #ifdef __MINGW32__ + __mingw_printf("%-6s: %s (%4d): %zd bytes at %p\n", reason, file, line, size, ptr); + #else + printf("%-6s: %s (%4d): %zd bytes at %p\n", reason, file, line, size, ptr); + #endif #endif }