Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: sizeof Data types Date: Tue, 09 Aug 2016 11:35:36 -0700 Organization: None to speak of Lines: 43 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="14202"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/irN374+AeqM0iknqR88FZ" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:HeIjkBsyOX688ciQpqNtOHJTVQg= sha1:1Zk4qWzNk7xu+ACR9DKFQtvgKjw= Xref: csiph.com comp.lang.c:92031 Ken Brody writes: > On 8/5/2016 6:45 PM, Real Troll wrote: >> >> Does this look right for various basic data types: >> >>> Storage size for char : 1 >>> Storage size for signed char : 1 >>> Storage size for unsigned char : 1 >>> Storage size for int : 4 >>> Storage size for unsigned int : 4 >>> Storage size for float : 4 >>> Storage size for double : 8 >>> Storage size for short : 2 >>> Storage size for unsigned short : 2 >>> Storage size for long : 4 >>> Storage size for unsigned long : 4 > > As noted elsethread, except for the three "char" variants, which must be 1, > the others can be virtually anything. (The only restrictions are that some > must be "at least" as large as something else -- such as "long" must be "at > least" as big as "int".) As discussed previously, the standard imposes requirements on the ranges, not the sizes. For example, the range of int must be at least -32767..+32767, the range of long must be at least -2147483647..+2147483647, and the range of int must be a subrange of the range of long. In the presence of an implausibly perverse number of padding bits, sizeof (int) *could* exceed sizeof (long) (by which I mean only that such an implementation would not violate the standard). > Note that, as far as C is concerned, all of the above could be "1". > (Given a sufficiently large CHAR_BITS.) Yes (except that it's CHAR_BIT). > The numbers you see above are probably typical for a 32-bit system. -- Keith Thompson (The_Other_Keith) kst-u@mib.org 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"