This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: [RFA:] stdint.h take 2: Add INTPTR_MIN, INTPTR_MAX, UINTPTR_MAX
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Hans-Peter Nilsson <hans-peter dot nilsson at axis dot com>
- Cc: newlib at sourceware dot org
- Date: Fri, 24 Apr 2009 13:23:23 +0000 (UTC)
- Subject: Re: [RFA:] stdint.h take 2: Add INTPTR_MIN, INTPTR_MAX, UINTPTR_MAX
- References: <200904092102.n39L28Sd018381@ignucius.se.axis.com>
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