diff --git a/sim_printf_fmts.h b/sim_printf_fmts.h index e31389381..e208cf958 100644 --- a/sim_printf_fmts.h +++ b/sim_printf_fmts.h @@ -5,6 +5,7 @@ * this header so that these formats are available to more than SCP. * * Author: B. Scott Michel + * C. Gauger-Cosgrove * * "scooter me fecit" *~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~*/ @@ -15,7 +16,9 @@ /* cross-platform printf() format specifiers: * * Note: MS apparently does recognize "ll" as "l" in its printf() routines, but "I64" is - * preferred for 64-bit types. + * preferred for 64-bit types. _MSC_VER and _WIN32 are always defined for Visual Studio + * builds. To check if the build is using 64-bit Visual Studio, you must check if the + * _WIN64 macro is defined. * * MinGW note: __MINGW64__ and __MINGW32__ are both defined by 64-bit gcc. Check * for __MINGW64__ before __MINGW32__. @@ -29,22 +32,26 @@ * POINTER_FMT: Format modifier for pointers, e.g. "%08" POINTER_FMT "X" */ -#if defined (_WIN32) || defined(_WIN64) - -# if defined(__MINGW64__) -# define LL_FMT "I64" -# define SIZE_T_FMT "I64" -# elif defined(_MSC_VER) || defined(__MINGW32__) -# define LL_FMT "ll" -# define SIZE_T_FMT "z" -# else - /* Graceful fail -- shouldn't ever default to this on a Windows platform. */ -# define LL_FMT "ll" -# define SIZE_T_FMT "I32" +#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__) +# if _MSC_VER >= 1900 || defined(__USE_MINGW_ANSI_STDIO) +/* VS 2015 or later, MinGW with ANSI stdio: Use the standard. Don't assume that + * MS or MinGW will support the "I" qualifier indefinitely. */ +# define SIZE_T_FMT "z" +# define T_UINT64_FMT "j" +# define T_INT64_FMT "j" +# elif (_MSC_VER < 1900 && defined(_WIN64)) || defined(__MINGW64__) +/* VS 2013 and earlier, 64-bit: use Microsoft's "I" qualifier. */ +# define SIZE_T_FMT "I64" +# define T_UINT64_FMT "I64" +# define T_INT64_FMT "I64" +# elif (_MSC_VER < 1900 && defined(_WIN32)) || defined(__MINGW32__) +/* VS 2013 and earlier, 32-bit: use Microsoft's "I" qualifier. */ +# define SIZE_T_FMT "I32" +# define T_UINT64_FMT "I64" +# define T_INT64_FMT "I64" # endif -# define T_UINT64_FMT "I64" -# define T_INT64_FMT "I64" +# define LL_FMT "ll" # define POINTER_FMT "p" #elif defined(__GNU_LIBRARY__) || defined(__GLIBC__) || defined(__GLIBC_MINOR__) || \