Re: short int always 16 bits or not?

Discussion in 'C Programming' started by James Kuyper, Apr 20, 2013.

  1. James Kuyper

    James Kuyper Guest

    On 04/19/2013 08:14 PM, Shriramana Sharma wrote:
    > Hello. I am reading the C99 standard as available from:
    > http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf


    You should look for n1570.pdf, which is the latest version of the
    standard. Nothing relevant to this discussion has changed, but other
    things have.

    > I note that it specifies (on p 34) macros defining the minimum and
    > maximum values of a short int corresponding to a size of 16 bits.
    > However it doesn't explicitly say that short int-s should be of 16
    > bits size. So can I trust short int-s to be 16 bits size or not?


    That's actually page 22. You should use the page number at the bottom of
    the page, rather than the page number shown by your PDF reader. I use
    Acrobat Reader, which refers to pages iii-xiv as pages 1-12; the real
    page 1 is referred to as page 13 by Acrobat Reader.

    It's even better to cite by section rather than by page number. That's
    partly because your citation can usually be more specific, but also
    because section numbers change less between different versions of the
    standard. That is section 5.2.4.2.1p1 in both n1256.pdf and n1570.pdf,
    even though it's on page 22 in the first, and on page 27 in the second.

    To answer your question, notice that earlier in the same section it
    says "Their implementation-defined values shall be equal or greater in
    magnitude(absolute value) to those shown, with the same sign." Consider
    the implications of "or greater". That means that an implementation is
    free to define SHRT_MAX as 65535, in which case 'short' would have to
    have 17 value bits, and an unspecified number of padding bits.

    > Also, doesn't prescribing #define-s for integer type min/max values
    > conflict with the general (?) understanding that the size of these
    > types are implementation defined? ...


    Since all that is prescribed is the minimum value for those #defines,
    with the actual value being implementation-defined, there is no conflict.

    ....
    > Finally, why would anyone want char to be other than 8 bits? *Is*
    > char on any platform *not* 8 bits?


    The single most popular alternative to 8-bit char is 16-bit char, which
    is the case on many DSPs.
    --
    James Kuyper
     
    James Kuyper, Apr 20, 2013
    #1
    1. Advertising

  2. James Kuyper <> writes:
    > On 04/19/2013 08:14 PM, Shriramana Sharma wrote:
    >> Hello. I am reading the C99 standard as available from:
    >> http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf

    >
    > You should look for n1570.pdf, which is the latest version of the
    > standard. Nothing relevant to this discussion has changed, but other
    > things have.


    Actually it's a draft of the latest version of the standard. It turns
    out there are a few (minor) differences between it and the official
    released standard

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Working, but not speaking, for JetHead Development, Inc.
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Apr 20, 2013
    #2
    1. Advertising

  3. James Kuyper

    James Kuyper Guest

    On 04/19/2013 11:06 PM, James Kuyper wrote:
    ....
    > ... That means that an implementation is
    > free to define SHRT_MAX as 65535, in which case 'short' would have to
    > have 17 value bits, ...


    Correction: 16 value bits and 1 sign bit.
     
    James Kuyper, Apr 22, 2013
    #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. Barry Schwarz

    Re: short int always 16 bits or not?

    Barry Schwarz, Apr 20, 2013, in forum: C Programming
    Replies:
    2
    Views:
    206
    glen herrmannsfeldt
    Apr 22, 2013
  2. Eric Sosman

    Re: short int always 16 bits or not?

    Eric Sosman, Apr 20, 2013, in forum: C Programming
    Replies:
    0
    Views:
    203
    Eric Sosman
    Apr 20, 2013
  3. Shriramana Sharma

    Re: short int always 16 bits or not?

    Shriramana Sharma, Apr 20, 2013, in forum: C Programming
    Replies:
    10
    Views:
    318
    Ken Brody
    Apr 25, 2013
  4. Les Cargill

    Re: short int always 16 bits or not?

    Les Cargill, Apr 20, 2013, in forum: C Programming
    Replies:
    0
    Views:
    188
    Les Cargill
    Apr 20, 2013
  5. Keith Thompson

    Re: short int always 16 bits or not?

    Keith Thompson, Apr 20, 2013, in forum: C Programming
    Replies:
    0
    Views:
    195
    Keith Thompson
    Apr 20, 2013
Loading...

Share This Page