wchar_t

Discussion in 'C++' started by Jens Theisen, Sep 28, 2006.

  1. Jens Theisen

    Jens Theisen Guest

    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
     
    Jens Theisen, Sep 28, 2006
    #1
    1. Advertising

  2. Jens Theisen

    P.J. Plauger Guest

    "Jens Theisen" <> wrote in message
    news:...

    > 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
     
    P.J. Plauger, Sep 28, 2006
    #2
    1. Advertising

  3. Jens Theisen

    Alan Johnson Guest

    P.J. Plauger wrote:
    > "Jens Theisen" <> wrote in message
    > news:...
    >
    > > 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
     
    Alan Johnson, Sep 28, 2006
    #3
  4. Jens Theisen

    Larry Smith Guest

    Alan Johnson wrote:
    > P.J. Plauger wrote:
    >> "Jens Theisen" <> wrote in message
    >> news:...
    >>
    >>> 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.
     
    Larry Smith, Sep 28, 2006
    #4
  5. Jens Theisen

    Alan Johnson Guest

    Larry Smith wrote:
    > Alan Johnson wrote:
    > > P.J. Plauger wrote:
    > >> "Jens Theisen" <> wrote in message
    > >> news:...
    > >>
    > >>> 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
     
    Alan Johnson, Sep 28, 2006
    #5
  6. Jens Theisen

    Jerry Coffin Guest

    In article <RGFSg.3421$Kw1.2848@trnddc05>, 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.
     
    Jerry Coffin, Sep 28, 2006
    #6
  7. Jens Theisen

    Ron Natalie Guest

    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.
     
    Ron Natalie, Sep 28, 2006
    #7
  8. Jens Theisen

    Jens Theisen Guest

    "P.J. Plauger" <> 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
     
    Jens Theisen, Sep 28, 2006
    #8
  9. Jens Theisen

    Gavin Deane Guest

    Jens Theisen wrote:
    > "P.J. Plauger" <> 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
     
    Gavin Deane, Sep 29, 2006
    #9
  10. Gavin Deane wrote:
    > Jens Theisen wrote:
    >> "P.J. Plauger" <> 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
     
    Victor Bazarov, Sep 29, 2006
    #10
  11. Jens Theisen

    Jens Theisen Guest

    "Gavin Deane" <> writes:

    > So, just like any other integral type, if you want to know the actual
    > size in your implementation [...]


    I quote from my last posting:

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


    You just told me that's it's not defined in the language:

    >, you need to consult your implementation.
    > sizeof L'x' is one easy way to do that. The answer may be different for
    > diifferent implementations.


    something which I have already stated in my first posting!

    Regards,

    Jens
     
    Jens Theisen, Sep 29, 2006
    #11
  12. Jens Theisen

    P.J. Plauger Guest

    "Jens Theisen" <> wrote in message
    news:...
    > "P.J. Plauger" <> 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.


    What you said was:

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

    P.J. Plauger
    Dinkumware, Ltd.
    http://www.dinkumware.com
     
    P.J. Plauger, Sep 30, 2006
    #12
  13. Jens Theisen

    Gavin Deane Guest

    Jens Theisen wrote:

    > "Gavin Deane" <> writes:
    >
    > > So, just like any other integral type, if you want to know the actual
    > > size in your implementation [...]

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

    >
    > You just told me that's it's not defined in the language:
    >
    > >, you need to consult your implementation.
    > > sizeof L'x' is one easy way to do that. The answer may be different for
    > > diifferent implementations.

    >
    > something which I have already stated in my first posting!


    So you already knew that the language does not specify the exact number
    of bits or bytes or octets or whatever in a wchar_t. And you already
    know that this implies that the size of wchar_t might be different in
    different implementations of the language. Since the suggestion that
    one way of finding out the size of wchar_t in your implementation is to
    do sizeof L'x' didn't seem to satisfy you, you presumably aren't asking
    "How do I find out the size of wchar_t in my implementation?"

    You originally asked "does anyone know which layer is responsible for
    defining the size of
    wchar_t?". I don't know what that question means. What do you mean by
    "layer"? The only sensible question I can think of in this context is,
    "How do I find out the size of wchar_t in my implementation?". So when
    I read your post, I couldn't understand your question as you wrote it,
    but I assumed you were asking "How do I find out the size of wchar_t in
    my implementation?" because that is the only question I could think
    that you might be trying to ask.

    Is that your question? Or is it something else? Or has it been answered
    already?

    Gavin Deane
     
    Gavin Deane, Sep 30, 2006
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Adrian Cornish
    Replies:
    2
    Views:
    8,246
    Adrian Cornish
    Jul 12, 2003
  2. Bren
    Replies:
    4
    Views:
    4,176
    Peter van Merkerk
    Oct 7, 2003
  3. sorty
    Replies:
    4
    Views:
    20,807
    Rolf Magnus
    Nov 25, 2003
  4. Jon Willeke

    wchar_t -> UTF-8?

    Jon Willeke, Feb 8, 2004, in forum: C++
    Replies:
    2
    Views:
    7,599
    Tilman Kuepper
    Feb 9, 2004
  5. Replies:
    3
    Views:
    1,154
    James Kanze
    Aug 15, 2008
Loading...

Share This Page