public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* again: sizeof(wchar_t)
@ 2004-04-24  9:21 Artem B. Bityuckiy
  2004-04-25 17:53 ` llewelly
  2004-04-26 11:45 ` Eljay Love-Jensen
  0 siblings, 2 replies; 7+ messages in thread
From: Artem B. Bityuckiy @ 2004-04-24  9:21 UTC (permalink / raw)
  To: gcc-help

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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-04-26 22:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-24  9:21 again: sizeof(wchar_t) Artem B. Bityuckiy
2004-04-25 17:53 ` llewelly
2004-04-25 20:47   ` Florian Weimer
2004-04-26 11:32     ` Artem B. Bityuckiy
2004-04-26 11:45 ` Eljay Love-Jensen
2004-04-26 18:25   ` Artem B. Bityuckiy
2004-04-26 22:50     ` Graham Nash

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).