]> Savannah Git Hosting - gnulib.git/commitdiff
stdint: Define [u]intptr_t correctly on 64-bit native Windows.
authorBruno Haible <bruno@clisp.org>
Mon, 18 Nov 2019 21:41:09 +0000 (22:41 +0100)
committerBruno Haible <bruno@clisp.org>
Mon, 18 Nov 2019 21:41:33 +0000 (22:41 +0100)
* lib/stdint.in.h (gl_intptr_t, gl_uintptr_t, INTPTR_MIN, INTPTR_MAX,
UINTPTR_MAX): Consider _WIN64.
* tests/test-stdint.c: Verify that [u]intptr_t is large enough to hold
a pointer.

ChangeLog
lib/stdint.in.h
tests/test-stdint.c

index 803dcd1a1cb5223aeecb8b0c08347eaeee3089db..5c8eed1ccbb7c12f1ca35abc427e6d91af35a7a6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2019-11-18  Bruno Haible  <bruno@clisp.org>
+
+       stdint: Define [u]intptr_t correctly on 64-bit native Windows.
+       * lib/stdint.in.h (gl_intptr_t, gl_uintptr_t, INTPTR_MIN, INTPTR_MAX,
+       UINTPTR_MAX): Consider _WIN64.
+       * tests/test-stdint.c: Verify that [u]intptr_t is large enough to hold
+       a pointer.
+
 2019-11-18  Bruno Haible  <bruno@clisp.org>
 
        stdint: Fix value of WINT_MAX when we override wint_t.
index e965c4a6cc76249afe4ee2571e77cf4e6becdb4c..37c15fc6b079e4c1b0627d4b4a6b03404fdf7997 100644 (file)
@@ -308,12 +308,17 @@ typedef gl_uint_fast32_t gl_uint_fast16_t;
    _findclose in <io.h>.  */
 # if !((defined __KLIBC__ && defined _INTPTR_T_DECLARED) \
        || (defined __MINGW32__ && defined _INTPTR_T_DEFINED && defined _UINTPTR_T_DEFINED))
-# undef intptr_t
-# undef uintptr_t
+#  undef intptr_t
+#  undef uintptr_t
+#  ifdef _WIN64
+typedef long long int gl_intptr_t;
+typedef unsigned long long int gl_uintptr_t;
+#  else
 typedef long int gl_intptr_t;
 typedef unsigned long int gl_uintptr_t;
-# define intptr_t gl_intptr_t
-# define uintptr_t gl_uintptr_t
+#  endif
+#  define intptr_t gl_intptr_t
+#  define uintptr_t gl_uintptr_t
 # endif
 
 /* 7.18.1.5. Greatest-width integer types */
@@ -490,9 +495,15 @@ typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t)
 # undef INTPTR_MIN
 # undef INTPTR_MAX
 # undef UINTPTR_MAX
-# define INTPTR_MIN  LONG_MIN
-# define INTPTR_MAX  LONG_MAX
-# define UINTPTR_MAX  ULONG_MAX
+# ifdef _WIN64
+#  define INTPTR_MIN  LLONG_MIN
+#  define INTPTR_MAX  LLONG_MAX
+#  define UINTPTR_MAX  ULLONG_MAX
+# else
+#  define INTPTR_MIN  LONG_MIN
+#  define INTPTR_MAX  LONG_MAX
+#  define UINTPTR_MAX  ULONG_MAX
+# endif
 
 /* 7.18.2.5. Limits of greatest-width integer types */
 
index a87830bf2b9ab264aed409d131985a7b74f1fb94..057d5e3039353ca5adcff890d3d77e456c8dc3e8 100644 (file)
@@ -217,12 +217,14 @@ err or;
 /* 7.18.2.4. Limits of integer types capable of holding object pointers */
 
 intptr_t g[3] = { 17, INTPTR_MIN, INTPTR_MAX };
+verify (sizeof (void *) <= sizeof (intptr_t));
 verify (TYPE_MINIMUM (intptr_t) == INTPTR_MIN);
 verify (TYPE_MAXIMUM (intptr_t) == INTPTR_MAX);
 verify_same_types (INTPTR_MIN, (intptr_t) 0 + 0);
 verify_same_types (INTPTR_MAX, (intptr_t) 0 + 0);
 
 uintptr_t h[2] = { 17, UINTPTR_MAX };
+verify (sizeof (void *) <= sizeof (uintptr_t));
 verify (TYPE_MAXIMUM (uintptr_t) == UINTPTR_MAX);
 verify_same_types (UINTPTR_MAX, (uintptr_t) 0 + 0);