1 
2 // It seems that latest min64-w64 compiler needs some help to avoid warnings; #4064
3 // It appears that its inttypes.h defines PRId64 to be I64 on Windows but then warns that
4 // I64 is not C99 too. Which is correct, but we know, and we don't want any warnings, and
5 // we can't control settings on CRAN. So here we try and isolate ourselves from all scenarios.
6 // There is a lot online about this, but these were a few that were most useful:
7 // https://stackoverflow.com/questions/23718110/error-unknown-conversion-type-character-l-in-format-scanning-long-long
8 // https://gitlab.freedesktop.org/nacho.garglez/cerbero/commit/4ec6bfdc1db1e4bc8d4278f53ad295af1efe89fb
9 // https://github.com/GNOME/glib/commit/98a0ab929d8c59ee27e5f470f11d077bb6a56749#diff-969b60ad3d206fd45c208e266ccfed38
10 // https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/
11 // Warning that __USE_MINGW_ANSI_STDIO could be deprecated:
12 // https://mingw-w64-public.narkive.com/aQDJHqCv/how-to-printf-64-bit-integer-in-64-bit-compiler-in-strict-iso-mode-with-all-warnings-enabled
13 // and then actual deprecation (with complaints) earlier in 2019 here:
14 // https://osdn.net/projects/mingw/lists/archive/users/2019-January/000202.html
15 // But I can't find _mingw.h. I can find mingw.h but not advice within it:
16 // https://github.com/git/git/blob/master/compat/mingw.h#L448
17 // The deprecation about I64 doesn't seem to take into account that lld throws the warning in MinGW:
18 //   warning: unknown conversion type character 'l' in format [-Wformat=]
19 // So let's see if the approach below works for now.
20 // If we need to make changes in future, we can do it here in one place.
21 
22 #ifndef DT_STDIO_H
23 #define DT_STDIO_H
24 #if defined(__MINGW32__) || (defined __MINGW64__)
25   #define __USE_MINGW_ANSI_STDIO 1
26   #include <stdio.h>
27   #define PRId64 "lld"
28   #define PRIu64 "llu"
29 #else
30   #include <stdio.h>
31   #include <inttypes.h>
32   // let inttypes.h decide: lld on Linux/C99; I64 on Windows Visual Studio for example
33 #endif
34 #endif
35