[RFA:] stdint.h take 2: Add INTPTR_MIN, INTPTR_MAX, UINTPTR_MAX

Joseph S. Myers joseph@codesourcery.com
Fri Apr 24 14:43:00 GMT 2009


On Thu, 9 Apr 2009, Hans-Peter Nilsson wrote:

>  #if defined(__PTRDIFF_TYPE__)
>  typedef signed __PTRDIFF_TYPE__ intptr_t;
>  typedef unsigned __PTRDIFF_TYPE__ uintptr_t;
> +#define INTPTR_MAX PTRDIFF_MAX
> +#define INTPTR_MIN PTRDIFF_MIN
> +#define UINTPTR_MAX (2UL * PTRDIFF_MAX + 1)

This UINTPTR_MAX definition is wrong (so causing gcc.dg/c99-stdint-1.c to 
fail) in the case where ptrdiff_t is int not long.  For long you want the 
2UL, for int you want 2U.  There doesn't seem to be an obvious way to get 
the right choice; OK to commit this patch to use __UINTPTR_MAX__ for 
compilers that define that (as is done with some other such macros where 
getting the right definition seems problematic without compiler support)?

2009-04-24  Joseph Myers  <joseph@codesourcery.com>

	* libc/include/stdint.h (UINTPTR_MAX): Define to __UINTPTR_MAX__
	if __UINTPTR_MAX__ defined.

Index: libc/include/stdint.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/stdint.h,v
retrieving revision 1.14
diff -u -r1.14 stdint.h
--- libc/include/stdint.h	16 Apr 2009 18:29:51 -0000	1.14
+++ libc/include/stdint.h	24 Apr 2009 13:20:37 -0000
@@ -244,7 +244,11 @@
 typedef unsigned __PTRDIFF_TYPE__ uintptr_t;
 #define INTPTR_MAX PTRDIFF_MAX
 #define INTPTR_MIN PTRDIFF_MIN
+#ifdef __UINTPTR_MAX__
+#define UINTPTR_MAX __UINTPTR_MAX__
+#else
 #define UINTPTR_MAX (2UL * PTRDIFF_MAX + 1)
+#endif
 #else
 /*
  * Fallback to hardcoded values, 

-- 
Joseph S. Myers
joseph@codesourcery.com



More information about the Newlib mailing list