[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[patches] RFC: Fix values of WCHAR_MIN and WCHAR_MAX



The ARM ABI requires wchar_t to be unsigned, which makes EGLIBC's
hard-coded default values for WCHAR_MAX and WCHAR_MIN incorrect.

Joseph, does this look all right to you?

ChangeLog.eglibc:
2007-09-27  Jim Blandy  <jimb@xxxxxxxxxxxxxxxx>

	* bits/wchar.h (__WCHAR_MIN, __WCHAR_MAX): Use information
	provided by GCC and the preprocessor's behavior to handle both
	signed and unsigned wchar_t ranges.

Index: bits/wchar.h
===================================================================
--- bits/wchar.h	(revision 3615)
+++ bits/wchar.h	(working copy)
@@ -20,7 +20,23 @@
 #ifndef _BITS_WCHAR_H
 #define _BITS_WCHAR_H	1
 
-#define __WCHAR_MIN	(-2147483647 - 1)
+/* Use GCC's __WCHAR_MAX__ when available.  */
+#ifdef __WCHAR_MAX__
+#define __WCHAR_MAX	__WCHAR_MAX__
+#else
 #define __WCHAR_MAX	(2147483647)
+#endif
 
+/* GCC may also define __WCHAR_UNSIGNED__.  */
+#ifdef __WCHAR_UNSIGNED__
+#define WCHAR_MIN       0
+
+/* Failing that, rely on the preprocessor's knowledge of the
+   signedness of wchar_t.  */
+#elif L'\0' - 1 > 0
+#define WCHAR_MIN       0
+#else
+#define WCHAR_MIN       (-WCHAR_MAX - 1)
+#endif
+
 #endif	/* bits/wchar.h */