This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC 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: again: sizeof(wchar_t)


I have built a GCC cross-compiler (Solaris and linux to our odd platform) and this automatically defines __WCHAR_TYPE__ which is used as the basis for a kind of definition of wchar_t:
typedef __WCHAR_TYPE__ __gwchar_t
(see inttypes.h). It appears to default to "int" so can be used in a sizeof(expression).


I'm using 3.2.2 so it may have all gotten changed since then.

--g

Artem B. Bityuckiy wrote:

Eljay Love-Jensen wrote:

Hi Artem,

Use:
#if WCHAR_BITSIZE == 16
blah blah blah
#elif WCHAR_BITSIZE == 32
blah blah blah
#else
#error Unsupported/unknown wchar_t bitsize.
#endif

When you are compiling your code with 32-bit wchar_t:
g++ -DWCHAR_BITSIZE=32 foo.cpp

When you are compiling your code with 16-bit wchar_t:
g++ -DWCHAR_BITSIZE=16 foo.cpp


The specific is that I'm upgrading Newlib itself. I'm adding locale and some C99 features support to it (Newlib isn't fully C99 complient). This is bad way to use such hack. This is like MAX_INT macro. Do you imagine, for example, glibc requires you to compile it with make CFLAGS+=-DMAX_INT=32? (this is just analogy) :-)
I hope there is some other way exists...


Thanks.




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