integral (non char) types allow padding?

Discussion in 'C++' started by Mihai Rusu, Aug 7, 2008.

  1. Mihai Rusu

    Mihai Rusu Guest

    Hello

    I am trying to figure out if the standard allows integral type representations with padding (ie value representation != object representation).

    A conforming implementation can have:
    - a 32bit int and 32bit unsigned int but have the unsigned int not use the sign bit for value representation? (so INT_MAX == UINT_MAX == 2^32-1)
    - a 33bit int and a 33bit unsigned int and both types have the 33th bit as padding?

    By reading 3.9.1 I suppose they can have padding.

    --
    Dizzy
     
    Mihai Rusu, Aug 7, 2008
    #1
    1. Advertising

  2. Mihai Rusu

    James Kanze Guest

    On Aug 7, 4:25 pm, Mihai Rusu <> wrote:

    > I am trying to figure out if the standard allows integral type
    > representations with padding (ie value representation !=
    > object representation).


    > A conforming implementation can have:
    > - a 32bit int and 32bit unsigned int but have the unsigned int
    > not use the sign bit for value representation? (so INT_MAX ==
    > UINT_MAX == 2^32-1)


    There has been some discussion about this recently, and
    apparently, the wording of the C++ standard doesn't allow this.
    I'm pretty sure that this was unintentional, however, as the C
    standard explicitly allows it, and it is necessary on machines
    with no hardware support for unsigned (Unisys MCP, for example).
    There is currently an open issue concerning it before the C++
    standards committee (active issue 689, open).

    > - a 33bit int and a 33bit unsigned int and both types have the
    > 33th bit as padding?


    > By reading 3.9.1 I suppose they can have padding.


    Certainly. On a Unisys MCP:
    CHAR_BIT == 8
    sizeof(int) == 6
    INT_MAX == 2^39
    UINT_MAX == 2^39
    48 bits, 8 padding, 1 sign. (Note that there can even be
    trapping representations. On the above, the 8 padding bits are
    required to be 0, although I'm not sure what happens if they
    aren't.)

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Aug 8, 2008
    #2
    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. Shailesh
    Replies:
    4
    Views:
    542
    Shailesh
    Apr 4, 2004
  2. Daniel Molina Wegener

    printf, padding integral double values

    Daniel Molina Wegener, Feb 14, 2005, in forum: C Programming
    Replies:
    2
    Views:
    654
    Martin Ambuhl
    Feb 14, 2005
  3. lovecreatesbeauty
    Replies:
    1
    Views:
    1,061
    Ian Collins
    May 9, 2006
  4. Ioannis Vranos
    Replies:
    11
    Views:
    763
    Ioannis Vranos
    Mar 28, 2008
  5. Ioannis Vranos

    Padding bits and char, unsigned char, signed char

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

Share This Page