__PRIPTR for 32-bit archs
Kornilios Kourtis
kkourt@inf.ethz.ch
Sun Feb 5 10:31:00 GMT 2012
Hi,
We are trying to use newlib in the Barrelfish research OS. Maybe I'm
missing something, but I think that the current definition of __PRIPTR()
in libc/include/inttypes.h is not correct for 32-bit archs.
I believe this fixes it:
--- src/newlib/libc/include/inttypes.h.orig 2012-02-04 15:00:18.943995069 +0100
+++ src/newlib/libc/include/inttypes.h 2012-02-04 16:41:05.468106414 +0100
@@ -242,16 +242,19 @@
#define SCNxMAX __SCNMAX(x)
/* ptr types */
+#if defined(__PTRDIFF_TYPE__)
#if __have_long64
#define __PRIPTR(x) __STRINGIFY(l##x)
#define __SCNPTR(x) __STRINGIFY(l##x)
-#elif __have_longlong64
-#define __PRIPTR(x) __STRINGIFY(ll##x)
-#define __SCNPTR(x) __STRINGIFY(ll##x)
#else
#define __PRIPTR(x) __STRINGIFY(x)
#define __SCNPTR(x) __STRINGIFY(x)
#endif
+#else /* !__PTRDIFF_TYPE__ */
+/* hardcoded values for uintptr_t (see stdint.h) */
+#define __PRIPTR(x) __STRINGIFY(l##x)
+#define __SCNPTR(x) __STRINGIFY(l##x)
+#endif
#define PRIdPTR __PRIPTR(d)
#define PRIiPTR __PRIPTR(i)
Also, since gcc seems to define __INTPTR_TYPE__ these days, you might
also want to consider something like the following (applied ontop of the
previous patch):
--- src/newlib/libc/include/stdint.h.old 2012-02-04 16:48:52.040115005 +0100
+++ src/newlib/libc/include/stdint.h 2012-02-04 17:00:00.804127320 +0100
@@ -235,19 +235,19 @@
typedef unsigned long uintmax_t;
#endif
-/*
- * GCC doesn't provide an appropriate macro for [u]intptr_t
- * For now, use __PTRDIFF_TYPE__
- */
-#if defined(__PTRDIFF_TYPE__)
-typedef signed __PTRDIFF_TYPE__ intptr_t;
-typedef unsigned __PTRDIFF_TYPE__ uintptr_t;
+#if defined(__INTPTR_TYPE__)
+typedef signed __INTPTR_TYPE__ intptr_t;
+typedef unsigned __INTPTR_TYPE__ uintptr_t;
+#ifdef __INTPTR_MAX__
+#define INTPTR_MAX __INTPTR_MAX__
+#else
#define INTPTR_MAX PTRDIFF_MAX
-#define INTPTR_MIN PTRDIFF_MIN
+#endif
+#define INTPTR_MIN (-INTPTR_MAX - 1)
#ifdef __UINTPTR_MAX__
#define UINTPTR_MAX __UINTPTR_MAX__
#else
-#define UINTPTR_MAX (2UL * PTRDIFF_MAX + 1)
+#define UINTPTR_MAX (2UL * INTPTR_MAX + 1)
#endif
#else
/*
--- src/newlib/libc/include/inttypes.h.old 2012-02-04 16:49:02.556115201 +0100
+++ src/newlib/libc/include/inttypes.h 2012-02-04 16:50:05.904116366 +0100
@@ -242,7 +242,7 @@
#define SCNxMAX __SCNMAX(x)
/* ptr types */
-#if defined(__PTRDIFF_TYPE__)
+#if defined(__INTPTR_TYPE__)
#if __have_long64
#define __PRIPTR(x) __STRINGIFY(l##x)
#define __SCNPTR(x) __STRINGIFY(l##x)
@@ -250,7 +250,7 @@
#define __PRIPTR(x) __STRINGIFY(x)
#define __SCNPTR(x) __STRINGIFY(x)
#endif
-#else /* !__PTRDIFF_TYPE__ */
+#else /* !__INTPTR_TYPE__ */
/* hardcoded values for uintptr_t (see stdint.h) */
#define __PRIPTR(x) __STRINGIFY(l##x)
#define __SCNPTR(x) __STRINGIFY(l##x)
cheers,
Kornilios.
--
Kornilios Kourtis
More information about the Newlib
mailing list