This is the mail archive of the
newlib@sources.redhat.com
mailing list for the newlib project.
Re: WCHAR_MAX question
- From: Jeff Johnston <jjohnstn at redhat dot com>
- To: "Artem B. Bityuckiy" <abityuckiy at yandex dot ru>
- Cc: newlib at sources dot redhat dot com
- Date: Tue, 04 May 2004 14:14:01 -0400
- Subject: Re: WCHAR_MAX question
- References: <408FFE45.2090401@yandex.ru> <409021B6.5080302@redhat.com> <4090A1E8.8000900@yandex.ru>
Artem B. Bityuckiy wrote:
The correct way it should be done is to have the compiler generate a
macro for it. As it turns out, the gcc compiler has __WCHAR_MAX__ as
one of it's default builtins which is why the code is defined as it
is. See c-cppbuiltin.c in the gcc directory.
For non-gcc compilers, we are defaulting the maximum value which I do
not think a bad thing as most wchar_t implementations use 4-byte
values for obvious reasons.
I agree that the most right way is to use GCC's predefined macro like
__WCHAR_MAX__. BUT! There is no such macro in gcc-3.2! What version of
gcc did you mention? I did 'grep -r WCHAR_MAX gcc-3.2/*' and didn't
found anything interesting...
I actually have a newer compiler: 3.4.0. I could find no sign of the
--with-short-wchar configuration option in my sources.
This really should be done by the compiler. The macro has to be a constant so
it cannot use sizeof() or make a function call (ala errno). Now, an end-user
can always specify the -fshort-wchar option on a compilation. As you can see,
this means that the macro should be dynamically defined by the compiler. The
newest gcc compiler has managed to do this right.
Even without the -fshort-wchar problem, calculating at configuration time is
going to be inaccurate. For a cross-target, an execution test would be
required, but we can't do that when we are in the stages of building the C
library. I guess we could check for the configuration option and set a flag in
newlib.h to handle the case you have mentioned.
-- Jeff J.