Skip to content

Commit 96e7418

Browse files
committed
SCP: Fix sim_printf_fmts.h for Visual Studio 2013 and older
Per Microsoft documentation, versions of Visual Studio from 2013 and below do not support the `hh`, `j`, `z`, and `t` format-type specifiers for `printf`, Microsoft's `I32` and `I64` specifiers are used instead. If the Visual Studio version supports the ANSI format-type spcifiers, they will be used. Furthermore, the preprocessor conditional selection logic was modified such that 64-bit Visual Studio versions are actually recognized.
1 parent c5d1f8c commit 96e7418

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

sim_printf_fmts.h

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* this header so that these formats are available to more than SCP.
66
*
77
* Author: B. Scott Michel
8+
* C. Gauger-Cosgrove
89
*
910
* "scooter me fecit"
1011
*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~*/
@@ -15,7 +16,9 @@
1516
/* cross-platform printf() format specifiers:
1617
*
1718
* Note: MS apparently does recognize "ll" as "l" in its printf() routines, but "I64" is
18-
* preferred for 64-bit types.
19+
* preferred for 64-bit types. _MSC_VER and _WIN32 are always defined for Visual Studio
20+
* builds. To check if the build is using 64-bit Visual Studio, you must check if the
21+
* _WIN64 macro is defined.
1922
*
2023
* MinGW note: __MINGW64__ and __MINGW32__ are both defined by 64-bit gcc. Check
2124
* for __MINGW64__ before __MINGW32__.
@@ -29,22 +32,26 @@
2932
* POINTER_FMT: Format modifier for pointers, e.g. "%08" POINTER_FMT "X"
3033
*/
3134

32-
#if defined (_WIN32) || defined(_WIN64)
33-
34-
# if defined(__MINGW64__)
35-
# define LL_FMT "I64"
36-
# define SIZE_T_FMT "I64"
37-
# elif defined(_MSC_VER) || defined(__MINGW32__)
38-
# define LL_FMT "ll"
39-
# define SIZE_T_FMT "z"
40-
# else
41-
/* Graceful fail -- shouldn't ever default to this on a Windows platform. */
42-
# define LL_FMT "ll"
43-
# define SIZE_T_FMT "I32"
35+
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
36+
# if _MSC_VER >= 1900 || defined(__USE_MINGW_ANSI_STDIO)
37+
/* VS 2015 or later, MinGW with ANSI stdio: Use the standard. Don't assume that
38+
* MS or MinGW will support the "I" qualifier indefinitely. */
39+
# define SIZE_T_FMT "z"
40+
# define T_UINT64_FMT "j"
41+
# define T_INT64_FMT "j"
42+
# elif (_MSC_VER < 1900 && defined(_WIN64)) || defined(__MINGW64__)
43+
/* VS 2013 and earlier, 64-bit: use Microsoft's "I" qualifier. */
44+
# define SIZE_T_FMT "I64"
45+
# define T_UINT64_FMT "I64"
46+
# define T_INT64_FMT "I64"
47+
# elif (_MSC_VER < 1900 && defined(_WIN32)) || defined(__MINGW32__)
48+
/* VS 2013 and earlier, 32-bit: use Microsoft's "I" qualifier. */
49+
# define SIZE_T_FMT "I32"
50+
# define T_UINT64_FMT "I64"
51+
# define T_INT64_FMT "I64"
4452
# endif
4553

46-
# define T_UINT64_FMT "I64"
47-
# define T_INT64_FMT "I64"
54+
# define LL_FMT "ll"
4855
# define POINTER_FMT "p"
4956

5057
#elif defined(__GNU_LIBRARY__) || defined(__GLIBC__) || defined(__GLIBC_MINOR__) || \

0 commit comments

Comments
 (0)