Does [stdint.h] guarantee two's complement form?

Discussion in 'C++' started by Alf P. Steinbach /Usenet, Sep 20, 2010.

  1. In the C99 standard draft N869, §7.18.2.1,

    minimum values of exact-width signed integer types
    INTn_MIN exactly either 1-2^(n-1) or -2^(n-1)

    where the first possibility is sign-and-magnitude and one's complement, and the
    second is for two's complement.

    However,

    http://en.wikipedia.org/wiki/Stdint.h#Exact-width_integer_types

    claims that

    intN_t must be encoded as a two's complement signed integer and uintN_t as an
    unsigned integer

    and later on goes into a discussion of how this guarantee can be troublesome.

    To some degree that claim is corroborated by

    http://www.opengroup.org/onlinepubs/9699919799/basedefs/stdint.h.html

    which states that, for the [stdint.h] that it defines,

    The typedef name int N _t designates a signed integer type with width N, no
    padding bits, and a two's-complement representation.

    but this may be just an additional Posix guarantee (although it's not marked as
    such).

    Which is correct wrt. to the C99 and C++0x [stdint.h]?


    Cheers,

    - Alf

    --
    blog at <url: http://alfps.wordpress.com>
     
    Alf P. Steinbach /Usenet, Sep 20, 2010
    #1
    1. Advertising

  2. Alf P. Steinbach /Usenet

    Ian Collins Guest

    On 09/20/10 01:18 PM, Alf P. Steinbach /Usenet wrote:
    > In the C99 standard draft N869, §7.18.2.1,
    >
    > minimum values of exact-width signed integer types
    > INTn_MIN exactly either 1-2^(n-1) or -2^(n-1)
    >
    > where the first possibility is sign-and-magnitude and one's complement,
    > and the second is for two's complement.
    >
    > However,
    >
    > http://en.wikipedia.org/wiki/Stdint.h#Exact-width_integer_types
    >
    > claims that
    >
    > intN_t must be encoded as a two's complement signed integer and uintN_t
    > as an
    > unsigned integer
    >
    > and later on goes into a discussion of how this guarantee can be
    > troublesome.
    >
    > To some degree that claim is corroborated by
    >
    > http://www.opengroup.org/onlinepubs/9699919799/basedefs/stdint.h.html
    >
    > which states that, for the [stdint.h] that it defines,
    >
    > The typedef name int N _t designates a signed integer type with width N, no
    > padding bits, and a two's-complement representation.
    >
    > but this may be just an additional Posix guarantee (although it's not
    > marked as such).
    >
    > Which is correct wrt. to the C99 and C++0x [stdint.h]?


    From C99:

    7.18.1.1 Exact-width integer types

    1 The typedef name intN_t designates a signed integer type with width N,
    no padding bits, and a two’s complement representation. Thus, int8_t
    denotes a signed integer type with a width of exactly 8 bits.

    --
    Ian Collins
     
    Ian Collins, Sep 20, 2010
    #2
    1. Advertising

  3. * Ian Collins, on 20.09.2010 03:24:
    > On 09/20/10 01:18 PM, Alf P. Steinbach /Usenet wrote:
    >> In the C99 standard draft N869, §7.18.2.1,
    >>
    >> minimum values of exact-width signed integer types
    >> INTn_MIN exactly either 1-2^(n-1) or -2^(n-1)
    >>
    >> where the first possibility is sign-and-magnitude and one's complement,
    >> and the second is for two's complement.
    >>
    >> However,
    >>
    >> http://en.wikipedia.org/wiki/Stdint.h#Exact-width_integer_types
    >>
    >> claims that
    >>
    >> intN_t must be encoded as a two's complement signed integer and uintN_t
    >> as an
    >> unsigned integer
    >>
    >> and later on goes into a discussion of how this guarantee can be
    >> troublesome.
    >>
    >> To some degree that claim is corroborated by
    >>
    >> http://www.opengroup.org/onlinepubs/9699919799/basedefs/stdint.h.html
    >>
    >> which states that, for the [stdint.h] that it defines,
    >>
    >> The typedef name int N _t designates a signed integer type with width N, no
    >> padding bits, and a two's-complement representation.
    >>
    >> but this may be just an additional Posix guarantee (although it's not
    >> marked as such).
    >>
    >> Which is correct wrt. to the C99 and C++0x [stdint.h]?

    >
    > From C99:
    >
    > 7.18.1.1 Exact-width integer types
    >
    > 1 The typedef name intN_t designates a signed integer type with width N, no
    > padding bits, and a two’s complement representation. Thus, int8_t denotes a
    > signed integer type with a width of exactly 8 bits.


    Thanks. The N869 draft leaves out the bit after the first comma.

    Cheers,

    - Alf

    --
    blog at <url: http://alfps.wordpress.com>
     
    Alf P. Steinbach /Usenet, Sep 20, 2010
    #3
    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. Mantorok Redgormor

    sign magnitude, ones complement, two's complement

    Mantorok Redgormor, Oct 5, 2003, in forum: C Programming
    Replies:
    8
    Views:
    8,611
    Glen Herrmannsfeldt
    Oct 8, 2003
  2. Jonas
    Replies:
    21
    Views:
    1,115
    Mark McIntyre
    Oct 14, 2003
  3. sarathy

    1's complement and 2's complement

    sarathy, Aug 1, 2006, in forum: C Programming
    Replies:
    20
    Views:
    2,197
    Bo Persson
    Aug 2, 2006
  4. sarathy
    Replies:
    22
    Views:
    2,355
    Bo Persson
    Aug 2, 2006
  5. Roberto Waltman

    2's complement vs. 1's complement vs. ...

    Roberto Waltman, Jun 9, 2011, in forum: C Programming
    Replies:
    4
    Views:
    1,359
    Michael Press
    Jun 14, 2011
Loading...

Share This Page