public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* size of wchar_t
@ 2004-03-31 19:48 Artem B. Bityuckiy
  2004-03-31 21:26 ` llewelly
  0 siblings, 1 reply; 5+ messages in thread
From: Artem B. Bityuckiy @ 2004-03-31 19:48 UTC (permalink / raw)
  To: gcc-help

Hello.

I need to determine size of wchar_t type at compile-time. Is there some 
macro to find sizeof(wchar_t). Specifically, I need to know is wchar_t 2 
bytes or more. I tried to use WCHAR_TYPE_SIZE macro but it isn't defined 
by gcc (I use arm-elf-gcc, v3.2). I also want such macro be defined on 
any target.

What macro should I use? May be some alternative ways exist? Thanks.

Thanks in advance.

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

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

* Re: size of wchar_t
  2004-03-31 19:48 size of wchar_t Artem B. Bityuckiy
@ 2004-03-31 21:26 ` llewelly
  2004-04-01  6:25   ` Artem B. Bityuckiy
  0 siblings, 1 reply; 5+ messages in thread
From: llewelly @ 2004-03-31 21:26 UTC (permalink / raw)
  To: Artem B. Bityuckiy; +Cc: gcc-help

"Artem B. Bityuckiy" <abityuckiy@yandex.ru> writes:

> Hello.
> 
> I need to determine size of wchar_t type at compile-time.

What do you mean by 'compile time'? sizeof(wchar_t) is compile time
    constant, but it isn't availibe for preprocessor conditionals.

> Is there
> some macro to find sizeof(wchar_t).

I can't find one. However, C99 requires <wchar.h> and <stdint.h> to
    provide WCHAR_MIN and WCHAR_MAX. You didn't say which C library
    you were using, but it would be easy to check. They are not quite
    what you want, but maybe they are close enough.

> Specifically, I need to know is
> wchar_t 2 bytes or more. I tried to use WCHAR_TYPE_SIZE macro but it
> isn't defined by gcc (I use arm-elf-gcc, v3.2). I also want such macro
> be defined on any target.
[snip]

The above macros are C99-specifc. :-( .

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

* Re: size of wchar_t
  2004-03-31 21:26 ` llewelly
@ 2004-04-01  6:25   ` Artem B. Bityuckiy
  2004-04-01 13:26     ` Eljay Love-Jensen
  0 siblings, 1 reply; 5+ messages in thread
From: Artem B. Bityuckiy @ 2004-04-01  6:25 UTC (permalink / raw)
  To: gcc-help

llewelly@xmission.com wrote:
> What do you mean by 'compile time'? sizeof(wchar_t) is compile time
>     constant, but it isn't availibe for preprocessor conditionals.
Sorry for inaccuracy. I meant 'preprocessing time'.
> 
> I can't find one. However, C99 requires <wchar.h> and <stdint.h> to
>     provide WCHAR_MIN and WCHAR_MAX. You didn't say which C library
>     you were using, but it would be easy to check. They are not quite
>     what you want, but maybe they are close enough.
I use Newlib, which isn't C99-compliant. To be more precise, I'm adding 
wide IO (C99 feature) to Newlib. I'll add these macros myself if needed.

But in general (as I understand), the size of wchar is defined by *gcc* 
(there is -fshort-wchar option). Therefore, some predefined *GCCs* macro 
should exist. All libc's macros (like WCHAR_MIN) should depend on this 
gcc's macro. But it seems Gnu libc defines WCHAR_MAX to 0xFFFFFFFF 
verbatim ... :-(
> The above macros are C99-specifc. :-( .

Any thoughts?

Thanks for help.
-- 
Best Regards,
Artem B. Bityuckiy,
St.-Petersburg, Russia.

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

* Re: size of wchar_t
  2004-04-01  6:25   ` Artem B. Bityuckiy
@ 2004-04-01 13:26     ` Eljay Love-Jensen
  2004-04-02 14:34       ` Artem B. Bityuckiy
  0 siblings, 1 reply; 5+ messages in thread
From: Eljay Love-Jensen @ 2004-04-01 13:26 UTC (permalink / raw)
  To: Artem B. Bityuckiy, gcc-help

Hi Artem,

I've used this trick in the past:

g++ -c -DWCHAR_BIT_SIZE=32 foo.cpp

On some platforms it is 31 bit (sufficient for ISO 10646); but I use 32 
even in that case, thus I'm including the fallow bit.  WCHAR_MAX will be 
0x7FFFFFFFu on those platforms.

g++ -c -DWCHAR_BIT_SIZE=16 -fshort-wchar foo.cpp

I then use the WCHAR_BIT_SIZE to alter code behavior.  Absence of 
WCHAR_BIT_SIZE causes a #error.

HTH,
--Eljay

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

* Re: size of wchar_t
  2004-04-01 13:26     ` Eljay Love-Jensen
@ 2004-04-02 14:34       ` Artem B. Bityuckiy
  0 siblings, 0 replies; 5+ messages in thread
From: Artem B. Bityuckiy @ 2004-04-02 14:34 UTC (permalink / raw)
  To: gcc-help; +Cc: Eljay Love-Jensen

Eljay Love-Jensen wrote:
> Hi Artem,
> 
> I've used this trick in the past:
> 
> g++ -c -DWCHAR_BIT_SIZE=32 foo.cpp
> 
> On some platforms it is 31 bit (sufficient for ISO 10646); but I use 32 
> even in that case, thus I'm including the fallow bit.  WCHAR_MAX will be 
> 0x7FFFFFFFu on those platforms.
> 
> g++ -c -DWCHAR_BIT_SIZE=16 -fshort-wchar foo.cpp
> 
> I then use the WCHAR_BIT_SIZE to alter code behavior.  Absence of 
> WCHAR_BIT_SIZE causes a #error.
>
I'll think about this, thanks.

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

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

end of thread, other threads:[~2004-04-02 14:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-31 19:48 size of wchar_t Artem B. Bityuckiy
2004-03-31 21:26 ` llewelly
2004-04-01  6:25   ` Artem B. Bityuckiy
2004-04-01 13:26     ` Eljay Love-Jensen
2004-04-02 14:34       ` Artem B. Bityuckiy

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).