WCHAR_MAX question

Artem B. Bityuckiy abityuckiy@yandex.ru
Wed Apr 28 20:11:00 GMT 2004


Hello.

I need to have correct WCHAR_MAX macro in newlib (WCHAR_MAX should be 
defined in wchar.h header according to SUSv3).

Currently there is the following in Newlib's wchar.h:

#ifndef WCHAR_MAX
#ifdef __WCHAR_MAX__
#define WCHAR_MAX __WCHAR_MAX__
#else
#define WCHAR_MAX 0x7fffffffu
#endif
#endif

In practice this means that WCHAR_MAX is always 0x7fffffffu because 
nobody defines WCHAR_MAX or __WCHAR_MAX__, even GCC.

 From one hand (a), WCHAR_MAX depends on target. Therefore it should be 
defined somewhere in target-dependent files.
 From other hand (b), WCHAR_MAX depends on sizeof(wchar_t). If 
sizeof(wchar_t) == 2, WCHAR_MAX is 0xFFFF, if sizeof(wchar_t) == 4, 
WCHAR_MAX is 0x7FFFFFFF.

----
What is corect ((a) or (b))?
----

I think (b), because for one target (say, arm-elf) I can generate either 
2 or 4 byte wchar_t. This depends on how I compile gcc. I can use 
--with-target-short-wchar configure script option when compile GCC and 
wchar_t will be 2 bytes. By default it is 4 bytes (at least for arm-elf 
target).

Currently, WCHAR_MAX in Newlib is 0x7fffffffu even if sizeof(wchar_t) is 
2. This is wrong of course.

 From other hand, gcc doesn't define any macro by which we can determine 
WCHAR_MAX as it does for example, for MAX_INT.

----
The second question is: how to define WCHAR_MAX macro correctly?
----

One way is to use autoconf. I has macro AC_CHECK_SIZEOF. But, Newlib 
uses very old autoconf (2.13) and it doesn't support this macro in 
cross-compilation environment...

Thanks in advance.

-- 
Best Regards,
Artem B. Bityuckiy,
St.-Petersburg, Russia.



More information about the Newlib mailing list