Padding bits and char, unsigned char, signed char

Discussion in 'C++' started by Ioannis Vranos, Mar 28, 2008.

  1. Under C++03:

    Is it guaranteed that char, unsigned char, signed char have no padding bits?
    Ioannis Vranos, Mar 28, 2008
    #1
    1. Advertising

  2. Ioannis Vranos wrote:
    > Under C++03:
    >
    > Is it guaranteed that char, unsigned char, signed char have no
    > padding bits?


    I can find no such guaranteed in the document (you still haven't
    got your own copy?)

    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, Mar 28, 2008
    #2
    1. Advertising

  3. Ioannis Vranos

    Ron Natalie Guest

    Ioannis Vranos wrote:
    > Under C++03:
    >
    > Is it guaranteed that char, unsigned char, signed char have no padding bits?


    Yes, the first paragraph of 3.9.1:

    For character types, all bits of
    the object representation participate in the value representation
    Ron Natalie, Mar 28, 2008
    #3
  4. Ioannis Vranos

    Ron Natalie Guest

    Victor Bazarov wrote:
    > Ioannis Vranos wrote:
    >> Under C++03:
    >>
    >> Is it guaranteed that char, unsigned char, signed char have no
    >> padding bits?

    >
    > I can find no such guaranteed in the document (you still haven't
    > got your own copy?)
    >
    > V

    3.9.1

    For character types, all bits of
    the object representation participate in the value representation
    Ron Natalie, Mar 28, 2008
    #4
  5. Ron Natalie wrote:
    > Ioannis Vranos wrote:
    >> Under C++03:
    >>
    >> Is it guaranteed that char, unsigned char, signed char have no padding
    >> bits?

    >
    > Yes, the first paragraph of 3.9.1:
    >
    > For character types, all bits of
    > the object representation participate in the value representation



    OK, thanks. The plural form "types" obviously contains char, signed char
    and unsigned char.
    Ioannis Vranos, Mar 28, 2008
    #5
  6. Ioannis Vranos wrote:
    > Is it guaranteed that char, unsigned char, signed char have no padding bits?


    Yes. Also, it is guaranteed that any combination of value forming bits
    in unsigned character type is a valid combination. There's no such
    guarantee for signed character type.

    --
    Best regards,
    Andrey Tarasevich
    Andrey Tarasevich, Mar 28, 2008
    #6
  7. Andrey Tarasevich wrote:
    > Ioannis Vranos wrote:
    >> Is it guaranteed that char, unsigned char, signed char have no padding
    >> bits?

    >
    > Yes. Also, it is guaranteed that any combination of value forming bits
    > in unsigned character type is a valid combination. There's no such
    > guarantee for signed character type.



    I suppose it is guaranteed for plain char too.
    Ioannis Vranos, Mar 28, 2008
    #7
  8. Ioannis Vranos wrote:
    >>> Is it guaranteed that char, unsigned char, signed char have no padding
    >>> bits?

    >> Yes. Also, it is guaranteed that any combination of value forming bits
    >> in unsigned character type is a valid combination. There's no such
    >> guarantee for signed character type.

    >
    > I suppose it is guaranteed for plain char too.


    Er.... Plain 'char' gets the same guarantees as the signed/unsigned char
    type it shares its representation with.

    This is actually why I used term 'character type' instead of 'char type'
    in my previous message. "Unsigned character type" refers to both
    'unsigned char' and 'char' on a platform where 'char' is unsigned. Same
    for signed.

    --
    Best regards,
    Andrey Tarasevich
    Andrey Tarasevich, Mar 28, 2008
    #8
  9. Andrey Tarasevich wrote:
    > Ioannis Vranos wrote:
    >>>> Is it guaranteed that char, unsigned char, signed char have no padding
    >>>> bits?
    >>> Yes. Also, it is guaranteed that any combination of value forming bits
    >>> in unsigned character type is a valid combination. There's no such
    >>> guarantee for signed character type.

    >>
    >> I suppose it is guaranteed for plain char too.

    >
    > Er.... Plain 'char' gets the same guarantees as the signed/unsigned char
    > type it shares its representation with.
    >
    > This is actually why I used term 'character type' instead of 'char type'
    > in my previous message. "Unsigned character type" refers to both
    > 'unsigned char' and 'char' on a platform where 'char' is unsigned. Same
    > for signed.



    I think there is a difference between C95 and C++03 on these. In both
    languages it is guaranteed that any POD type can be treated as a
    sequence of unsigned chars. I do not remember which language also
    permits to be treated as a sequence of plain chars and/or-not signed chars.
    Ioannis Vranos, Mar 28, 2008
    #9
  10. Ioannis Vranos

    Ron Natalie Guest

    Ioannis Vranos wrote:

    >
    > I think there is a difference between C95 and C++03 on these. In both
    > languages it is guaranteed that any POD type can be treated as a
    > sequence of unsigned chars. I do not remember which language also
    > permits to be treated as a sequence of plain chars and/or-not signed chars.


    char, unsigned char, signed char. None can have padding bits in C++.
    PODS can be copied to arrays of "char" or "unsigned char". Signed
    char behavior isn't specified.

    In C (99, what the fark is 95?), you are right. It only makes
    guarantees for unsigned char.
    Ron Natalie, Mar 28, 2008
    #10
  11. Ioannis Vranos

    Default User Guest

    Ron Natalie wrote:


    > In C (99, what the fark is 95?)


    C89 with some corrections.



    Brian
    Default User, Mar 28, 2008
    #11
  12. Ron Natalie wrote:
    > Ioannis Vranos wrote:
    >
    >>
    >> I think there is a difference between C95 and C++03 on these. In both
    >> languages it is guaranteed that any POD type can be treated as a
    >> sequence of unsigned chars. I do not remember which language also
    >> permits to be treated as a sequence of plain chars and/or-not signed
    >> chars.

    >
    > char, unsigned char, signed char. None can have padding bits in C++.
    > PODS can be copied to arrays of "char" or "unsigned char". Signed
    > char behavior isn't specified.
    >
    > In C (99, what the fark is 95?), you are right. It only makes
    > guarantees for unsigned char.



    OK, thanks for the clarification. C95 is ISO/IEC 9899:1995 - Amendment 1.

    Basically it is C90+ 3 standard header files, <wchar.h>, <wctype.h>,
    <iso646.h>.


    C95 is really the C "subset" of C++98, not C90.
    Ioannis Vranos, Mar 28, 2008
    #12
    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. sarmin kho
    Replies:
    2
    Views:
    815
    A. Lloyd Flanagan
    Jun 15, 2004
  2. Miki Tebeka
    Replies:
    1
    Views:
    430
    Marcin 'Qrczak' Kowalczyk
    Jun 14, 2004
  3. Steffen Fiksdal

    void*, char*, unsigned char*, signed char*

    Steffen Fiksdal, May 8, 2005, in forum: C Programming
    Replies:
    1
    Views:
    569
    Jack Klein
    May 9, 2005
  4. Ioannis Vranos

    Padding bits and char, unsigned char, signed char

    Ioannis Vranos, Mar 28, 2008, in forum: C Programming
    Replies:
    6
    Views:
    599
    Ben Bacarisse
    Mar 29, 2008
  5. Ioannis Vranos

    Padding bits in signed char

    Ioannis Vranos, Apr 14, 2009, in forum: C++
    Replies:
    5
    Views:
    842
    James Kanze
    Apr 15, 2009
Loading...

Share This Page