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]

again: sizeof(wchar_t)


Hello guys. I have already asked this (http://gcc.gnu.org/ml/gcc-help/2004-03/msg00350.html). May be this time I'll be lucky and get more answers...

I'm writing some code that depends on sizeof(wchar_t). If sizeof(wchar_t) > 2 I'm doing one things, if sizeof(wchar_t) = 2 - another things. I need to determine sizeof(wchar_t) in precompiler. How can I do this?

My logic is: sizeof(wchar_t) is given by gcc. I can use --with-target-short-wchar gcc's configure script option and gcc will generate 2-byte wchar_t variables. Therefore, there must be some predefined GCC's macro using which I can determine the size of wchar_t. Right?

The code for which I need to know sizeof(wchar_t) is written for Newlib (small standard C library). As I understand situation with wchar_t is similar to situation with other basic C types - they are defined with help of gcc's stddef.h or limits.h.

llewelly advised me to use WCHAR_MAX macro.

I tried to use something like this:

#if WCHAR_MAX > 0xFFFF
blablabla
#else
blablabla
#endif

But to my surprise I've found out that I have WCHAR_MAX==0x7FFFFFFFu when sizeof(wchar_t)==2! I've seen into wchar.h of Newlib - there is something like

#ifndef _WCHAR_MAX
#define WCHAR_MAX 0x7FFFFFFFu
#else
#define WCHAR_MAX _WCHAR_MAX
#else

This is similar to defines of other limits macros. I've seen to GCC's headers and not found any _WCHAR_MAX reference there.

I have seen to other libc's (FreeBSD's and Glibc) - they also rely on _WCHAR_MAX, but _WCHAR_MAX isn't from GCC, but is from target-depended files (also placed in that libc) as I've understood.

Therefore I can conclude that sizeof(wchar_t) is considered as target-dependent. An I can't vary gcc (using or not --with-target-short-wchar option when compiling it)...

But I want to have one target that is built differently depending on sizeof(wchar_t) that is defined by GCC. How can I do this?

One obvious way is to use construction like

if (sizeof(wchar_t) > 2)
  {
    blablabala
  }
else
  {
    blablabla
  }

but I want to rely on precompiler, not on compiler.

What should I do?

Thanks.

P.S. Please, CC to me if answer...

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


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