This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Update newlib so that it passes libc++'s tests



On 12/17/2013 04:42 AM, Corinna Vinschen wrote:
On Dec 16 16:54, JF Bastien wrote:
+#ifndef WCHAR_MAX
  #ifdef __WCHAR_MAX__
  #define WCHAR_MAX __WCHAR_MAX__
+#elif defined(__WCHAR_UNSIGNED__)
+#define WCHAR_MAX 0xffffffffu
+#else
+#define WCHAR_MAX 0x7fffffffu
  #endif
and this is not quite ok.  You're assuming that wchar_t is 4 bytes, but it
isn't on all platforms.  The fallbacks should take that into account,
along the lines of

   #define WCHAR_MAX ((wchar_t)-1)


Unfortunately, this is not OK in general, as *_MAX defines are required to be able to be used in preprocessor expressions, and casts are not always allowed in them. ("The expression that controls conditional inclusion shall be an integer constant expression except that: it shall not contain a cast; ...") I tried it with GCC 4.4.7 and it works, but since the standard expressly forbids it, it probably is not good to do.
                Craig

#define WCHAR_MAX ((wchar_t)-1)

#if WCHAR_MAX == -1
  #include <stdint.h>
 #else
  #error "!-1"
#endif


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]