Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: short int always 16 bits or not?

Reply
Thread Tools

Re: short int always 16 bits or not?

 
 
James Kuyper
Guest
Posts: n/a
 
      04-20-2013
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/WG...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
 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      04-20-2013
James Kuyper <(E-Mail Removed)> 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/WG...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.velocityreviews.com/forums/(E-Mail Removed) <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"
 
Reply With Quote
 
 
 
 
James Kuyper
Guest
Posts: n/a
 
      04-22-2013
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: short int always 16 bits or not? Shriramana Sharma C Programming 10 04-25-2013 01:46 PM
Re: short int always 16 bits or not? Barry Schwarz C Programming 2 04-22-2013 06:39 PM
Re: short int always 16 bits or not? Eric Sosman C Programming 0 04-20-2013 01:04 AM
8-Bits vs 12 or 16 bits/pixel; When does more than 8 bits count ? Al Dykes Digital Photography 3 12-29-2003 07:08 PM
dirty stuff: f(int,int) cast to f(struct{int,int}) Schnoffos C Programming 2 06-27-2003 03:13 AM



Advertisments