This is the mail archive of the newlib@sources.redhat.com 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: WCHAR_MAX question


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.



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