You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2020/11/19 08:50:37 UTC

[incubator-nuttx] 32/34: sim: Make int64_t match the host OS

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit a863fa30f966834d126dacab56b80534f10b6b15
Author: YAMAMOTO Takashi <ya...@midokura.com>
AuthorDate: Tue Nov 10 14:39:17 2020 +0900

    sim: Make int64_t match the host OS
---
 arch/sim/include/inttypes.h | 36 +++++++++++++++++++++++-------------
 arch/sim/include/types.h    | 10 ++++++++++
 2 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/arch/sim/include/inttypes.h b/arch/sim/include/inttypes.h
index c45e110..68f2dd5 100644
--- a/arch/sim/include/inttypes.h
+++ b/arch/sim/include/inttypes.h
@@ -44,78 +44,88 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+#if defined(CONFIG_HOST_MACOS)
+#  define _PRI64PREFIX "ll"
+#  define _SCN64PREFIX "ll"
+#  define INT64_C(x)  x ## ll
+#  define UINT64_C(x) x ## ull
+#else
+#  define _PRI64PREFIX "l"
+#  define _SCN64PREFIX "l"
+#  define INT64_C(x)  x ## l
+#  define UINT64_C(x) x ## ul
+#endif
+
 #  define PRId8       "d"
 #  define PRId16      "d"
 #  define PRId32      "d"
-#  define PRId64      "lld"
+#  define PRId64      _PRI64PREFIX "d"
 
 #  define PRIi8       "i"
 #  define PRIi16      "i"
 #  define PRIi32      "i"
-#  define PRIi64      "lli"
+#  define PRIi64      _PRI64PREFIX "i"
 
 #  define PRIo8       "o"
 #  define PRIo16      "o"
 #  define PRIo32      "o"
-#  define PRIo64      "llo"
+#  define PRIo64      _PRI64PREFIX "o"
 
 #  define PRIu8       "u"
 #  define PRIu16      "u"
 #  define PRIu32      "u"
-#  define PRIu64      "llu"
+#  define PRIu64      _PRI64PREFIX "u"
 
 #  define PRIuMAX     "llu"
 
 #  define PRIx8       "x"
 #  define PRIx16      "x"
 #  define PRIx32      "x"
-#  define PRIx64      "llx"
+#  define PRIx64      _PRI64PREFIX "x"
 
 #  define PRIX8       "X"
 #  define PRIX16      "X"
 #  define PRIX32      "X"
-#  define PRIX64      "llX"
+#  define PRIX64      _PRI64PREFIX "X"
 
 #  define SCNd8       "hhd"
 #  define SCNd16      "hd"
 #  define SCNd32      "d"
-#  define SCNd64      "lld"
+#  define SCNd64      _SCN64PREFIX "d"
 
 #  define SCNdMAX     "lld"
 
 #  define SCNi8       "hhi"
 #  define SCNi16      "hi"
 #  define SCNi32      "i"
-#  define SCNi64      "lli"
+#  define SCNi64      _SCN64PREFIX "i"
 
 #  define SCNiMAX     "lli"
 
 #  define SCNo8       "hho"
 #  define SCNo16      "ho"
 #  define SCNo32      "o"
-#  define SCNo64      "llo"
+#  define SCNo64      _SCN64PREFIX "o"
 
 #  define SCNoMAX     "llo"
 
 #  define SCNu8       "hhu"
 #  define SCNu16      "hu"
 #  define SCNu32      "u"
-#  define SCNu64      "llu"
+#  define SCNu64      _SCN64PREFIX "u"
 
 #  define SCNx8       "hhx"
 #  define SCNx16      "hx"
 #  define SCNx32      "x"
-#  define SCNx64      "llx"
+#  define SCNx64      _SCN64PREFIX "x"
 
 #  define INT8_C(x)   x
 #  define INT16_C(x)  x
 #  define INT32_C(x)  x
-#  define INT64_C(x)  x ## ll
 
 #  define UINT8_C(x)  x
 #  define UINT16_C(x) x
 #  define UINT32_C(x) x ## u
-#  define UINT64_C(x) x ## ull
 
 #if defined(CONFIG_HOST_X86_64) && !defined(CONFIG_SIM_M32)
 #  define PRIdPTR     "ld"
diff --git a/arch/sim/include/types.h b/arch/sim/include/types.h
index 1baf4a7..955e189 100644
--- a/arch/sim/include/types.h
+++ b/arch/sim/include/types.h
@@ -72,8 +72,18 @@ typedef unsigned short     _uint16_t;
 typedef signed int         _int32_t;
 typedef unsigned int       _uint32_t;
 
+/* Note about host OS types:
+ * - int64_t is long long for 64-bit macOS
+ * - int64_t is long for Ubuntu x86-64
+ */
+
+#if defined(CONFIG_HOST_MACOS) || !defined(_LP64)
 typedef signed long long   _int64_t;
 typedef unsigned long long _uint64_t;
+#else
+typedef signed long        _int64_t;
+typedef unsigned long      _uint64_t;
+#endif
 #define __INT64_DEFINED
 
 #if defined(__APPLE_CC__)