[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [patches] RFC: Fix values of WCHAR_MIN and WCHAR_MAX
- To: "Joseph S. Myers" <joseph@xxxxxxxxxxxxxxxx>
- Subject: Re: [patches] RFC: Fix values of WCHAR_MIN and WCHAR_MAX
- From: Jim Blandy <jimb@xxxxxxxxxxxxxxxx>
- Date: Fri, 28 Sep 2007 15:04:57 -0700
"Joseph S. Myers" <joseph@xxxxxxxxxxxxxxxx> writes:
> On Fri, 28 Sep 2007, Jim Blandy wrote:
>
>> +#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
>
> Both these values of WCHAR_MIN should be L'\0' not plain 0, so they have
> the correct (unsigned) type. It looks correct with that change.
Thanks for the review. I've committed the following:
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,24 @@
#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__.
+ Use L'\0' to give the expression the correct (unsigned) type. */
+#ifdef __WCHAR_UNSIGNED__
+#define WCHAR_MIN L'\0'
+
+/* Failing that, rely on the preprocessor's knowledge of the
+ signedness of wchar_t. */
+#elif L'\0' - 1 > 0
+#define WCHAR_MIN L'\0'
+#else
+#define WCHAR_MIN (-WCHAR_MAX - 1)
+#endif
+
#endif /* bits/wchar.h */