Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > wchar_t

Reply
Thread Tools

wchar_t

 
 
Jens Theisen
Guest
Posts: n/a
 
      09-27-2006
Hello,

does anyone know which layer is responsible for defining the size of
wchar_t?

Naturally enough, it's not defined in the language. I looked in the
SystemV processor supplement and the Itanium C++ ABI which are
authorative for my platform, but there is no mentioning of this.

The manual of the compiler I'm using, gcc, doesn't tell me either.

Does anyone know more?

Cheers,

Jens
 
Reply With Quote
 
 
 
 
P.J. Plauger
Guest
Posts: n/a
 
      09-28-2006
"Jens Theisen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> does anyone know which layer is responsible for defining the size of
> wchar_t?
>
> Naturally enough, it's not defined in the language.


Naturally enough, it is. L'x' has type wchar_t, so sizeof L'x'
tells you the size of wchar_t.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com


 
Reply With Quote
 
 
 
 
Alan Johnson
Guest
Posts: n/a
 
      09-28-2006

P.J. Plauger wrote:
> "Jens Theisen" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
> > does anyone know which layer is responsible for defining the size of
> > wchar_t?
> >
> > Naturally enough, it's not defined in the language.

>
> Naturally enough, it is. L'x' has type wchar_t, so sizeof L'x'
> tells you the size of wchar_t.
>


The part that does not seem natural to me is the name "wchar_t". We
don't have types "int_t", "char_t", "bool_t", etc. I'm sure there is a
good reason for "wchar_t" instead of "wchar", but that doesn't mean it
isn't still ugly.

--
Alan Johnson

 
Reply With Quote
 
Larry Smith
Guest
Posts: n/a
 
      09-28-2006
Alan Johnson wrote:
> P.J. Plauger wrote:
>> "Jens Theisen" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>
>>> does anyone know which layer is responsible for defining the size of
>>> wchar_t?
>>>
>>> Naturally enough, it's not defined in the language.

>> Naturally enough, it is. L'x' has type wchar_t, so sizeof L'x'
>> tells you the size of wchar_t.
>>

>
> The part that does not seem natural to me is the name "wchar_t". We
> don't have types "int_t", "char_t", "bool_t", etc. I'm sure there is a
> good reason for "wchar_t" instead of "wchar", but that doesn't mean it
> isn't still ugly.
>


Because it is a typedef, rather than a built-in native type.(?)
That puts it in the same category as 'int16_t', 'int32_t', etc
from 'stdint.h', size_t, fpos_t, ptrdiff_t, etc, etc.
 
Reply With Quote
 
Alan Johnson
Guest
Posts: n/a
 
      09-28-2006

Larry Smith wrote:
> Alan Johnson wrote:
> > P.J. Plauger wrote:
> >> "Jens Theisen" <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed)...
> >>
> >>> does anyone know which layer is responsible for defining the size of
> >>> wchar_t?
> >>>
> >>> Naturally enough, it's not defined in the language.
> >> Naturally enough, it is. L'x' has type wchar_t, so sizeof L'x'
> >> tells you the size of wchar_t.
> >>

> >
> > The part that does not seem natural to me is the name "wchar_t". We
> > don't have types "int_t", "char_t", "bool_t", etc. I'm sure there is a
> > good reason for "wchar_t" instead of "wchar", but that doesn't mean it
> > isn't still ugly.
> >

>
> Because it is a typedef, rather than a built-in native type.(?)
> That puts it in the same category as 'int16_t', 'int32_t', etc
> from 'stdint.h', size_t, fpos_t, ptrdiff_t, etc, etc.


According to 2.11.1 wchar_t is a keyword. It has the restriction that
it must have the same storage and alignment requirements as some other
integral type, like it would if it were a typedef, but it is in fact a
first class type.

--
Alan Johnson

 
Reply With Quote
 
Jerry Coffin
Guest
Posts: n/a
 
      09-28-2006
In article <RGFSg.3421$Kw1.2848@trnddc05>, http://www.velocityreviews.com/forums/(E-Mail Removed) says...

[ ... why 'wchar_t' instead of 'wchar' ?]

> Because it is a typedef, rather than a built-in native type.(?)
> That puts it in the same category as 'int16_t', 'int32_t', etc
> from 'stdint.h', size_t, fpos_t, ptrdiff_t, etc, etc.


In C++, it's a native type -- but when originally devised as part of the
C89 standard, it was a typedef.

--
Later,
Jerry.

The universe is a figment of its own imagination.
 
Reply With Quote
 
Ron Natalie
Guest
Posts: n/a
 
      09-28-2006
Alan Johnson wrote:

> The part that does not seem natural to me is the name "wchar_t". We
> don't have types "int_t", "char_t", "bool_t", etc. I'm sure there is a
> good reason for "wchar_t" instead of "wchar", but that doesn't mean it
> isn't still ugly.
>


It's because it came relatively later in the history of C and C++.
In C it is a typedef typically. In C++ in needs to be a real type.
 
Reply With Quote
 
Jens Theisen
Guest
Posts: n/a
 
      09-28-2006
"P.J. Plauger" <(E-Mail Removed)> writes:

> > Naturally enough, it's not defined in the language.

>
> Naturally enough, it is. L'x' has type wchar_t, so sizeof L'x'
> tells you the size of wchar_t.


I think I was quite explicit in my posting that I'm not wondering
about how big it is, but where it's defined.

Regards,

Jens
 
Reply With Quote
 
Gavin Deane
Guest
Posts: n/a
 
      09-29-2006

Jens Theisen wrote:
> "P.J. Plauger" <(E-Mail Removed)> writes:
>
> > > Naturally enough, it's not defined in the language.

> >
> > Naturally enough, it is. L'x' has type wchar_t, so sizeof L'x'
> > tells you the size of wchar_t.

>
> I think I was quite explicit in my posting that I'm not wondering
> about how big it is, but where it's defined.


3.9.1/5
Type wchar_t is a distinct type whose values can represent distinct
codes for all members of the largest extended character set specified
among the supported locales (22.1.1). Type wchar_t shall have the same
size, signedness, and alignment requirements (3.9) as one of the other
integral types, called its underlying type.

So, just like any other integral type, if you want to know the actual
size in your implementation, you need to consult your implementation.
sizeof L'x' is one easy way to do that. The answer may be different for
diifferent implementations.

Gavin Deane

 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      09-29-2006
Gavin Deane wrote:
> Jens Theisen wrote:
>> "P.J. Plauger" <(E-Mail Removed)> writes:
>>
>>>> Naturally enough, it's not defined in the language.
>>>
>>> Naturally enough, it is. L'x' has type wchar_t, so sizeof L'x'
>>> tells you the size of wchar_t.

>>
>> I think I was quite explicit in my posting that I'm not wondering
>> about how big it is, but where it's defined.

>
> 3.9.1/5
> Type wchar_t is a distinct type whose values can represent distinct
> codes for all members of the largest extended character set specified
> among the supported locales (22.1.1). Type wchar_t shall have the same
> size, signedness, and alignment requirements (3.9) as one of the other
> integral types, called its underlying type.
>
> So, just like any other integral type, if you want to know the actual
> size in your implementation, you need to consult your implementation.
> sizeof L'x' is one easy way to do that. The answer may be different
> for diifferent implementations.


I'd probably use 'std::numeric_limits<wchar_t>' or traits template
specialised on 'wchar_t' to find out more about it, not 'sizeof'.
After all, sizeof(int), sizeof(unsigned), sizeof(long) and sizeof(
unsigned long), are all the same on many 32-bit platforms I know.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
converting from windows wchar_t to linux wchar_t yakir22@gmail.com C++ 3 08-15-2008 09:04 AM
wchar_t -> UTF-8? Jon Willeke C++ 2 02-09-2004 08:05 AM
std::wstring, TCHAR, wchar_t and LPTSTR sorty C++ 4 11-25-2003 11:05 AM
string class that can convert between wchar_t and char Bren C++ 4 10-07-2003 03:24 PM
wchar_t wstring char string transformations Adrian Cornish C++ 2 07-12-2003 08:05 PM



Advertisments