Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Minimum sizes of integral and floating point types

Reply
Thread Tools

Minimum sizes of integral and floating point types

 
 
Ioannis Vranos
Guest
Posts: n/a
 
      03-08-2008
About C95.

Is there any mentioning in the standard about the number of usable bits
of the various built in types, apart from char/signed char/unsigned char
types? Or only about the minimum value ranges of them?
 
Reply With Quote
 
 
 
 
jacob navia
Guest
Posts: n/a
 
      03-09-2008
Ioannis Vranos wrote:
> About C95.
>
> Is there any mentioning in the standard about the number of usable bits
> of the various built in types, apart from char/signed char/unsigned char
> types? Or only about the minimum value ranges of them?


1) C95 is not a standard. It is obsoleted by C99.

2) Use C99 int32_t, int64_t, etc


--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
 
Reply With Quote
 
 
 
 
Ioannis Vranos
Guest
Posts: n/a
 
      03-09-2008
jacob navia wrote:
> Ioannis Vranos wrote:
>> About C95.
>>
>> Is there any mentioning in the standard about the number of usable
>> bits of the various built in types, apart from char/signed
>> char/unsigned char types? Or only about the minimum value ranges of them?

>
> 1) C95 is not a standard.



What do you mean it isn't a standard? Of course it is.


> It is obsoleted by C99.
>
> 2) Use C99 int32_t, int64_t, etc



I want to program in C95.
 
Reply With Quote
 
Ben Pfaff
Guest
Posts: n/a
 
      03-09-2008
Ioannis Vranos <(E-Mail Removed)> writes:

> Is there any mentioning in the standard about the number of usable
> bits of the various built in types, apart from char/signed
> char/unsigned char types? Or only about the minimum value ranges of
> them?


I am not sure exactly what you are after. If you want the number
of bits in a given type, including any sign and padding bits,
then CHAR_BIT*sizeof(type) will give you the answer. If you want
the number of value bits, then you can figure it out from the
type's range, although the calculation for that is not as simple.
--
char a[]="\n .CJacehknorstu";int putchar(int);int main(void){unsigned long b[]
={0x67dffdff,0x9aa9aa6a,0xa77ffda9,0x7da6aa6a,0xa6 7f6aaa,0xaa9aa9f6,0x11f6},*p
=b,i=24;for(;p+=!*p;*p/=4)switch(0[p]&3)case 0:{return 0;for(p--;i--;i--)case+
2:{i++;if(i)break;else default:continue;if(0)case 1utchar(a[i&15]);break;}}}
 
Reply With Quote
 
Ioannis Vranos
Guest
Posts: n/a
 
      03-09-2008
Ben Pfaff wrote:
> Ioannis Vranos <(E-Mail Removed)> writes:
>
>> Is there any mentioning in the standard about the number of usable
>> bits of the various built in types, apart from char/signed
>> char/unsigned char types? Or only about the minimum value ranges of
>> them?

>
> I am not sure exactly what you are after. If you want the number
> of bits in a given type, including any sign and padding bits,
> then CHAR_BIT*sizeof(type) will give you the answer. If you want
> the number of value bits, then you can figure it out from the
> type's range, although the calculation for that is not as simple.



In other words my question is this. Does C95 specify that long must be
at least 32 bits, or it only provides the minimum value ranges?
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      03-09-2008
Ioannis Vranos <(E-Mail Removed)> writes:
> Ben Pfaff wrote:
>> Ioannis Vranos <(E-Mail Removed)> writes:
>>> Is there any mentioning in the standard about the number of usable
>>> bits of the various built in types, apart from char/signed
>>> char/unsigned char types? Or only about the minimum value ranges of
>>> them?

>>
>> I am not sure exactly what you are after. If you want the number
>> of bits in a given type, including any sign and padding bits,
>> then CHAR_BIT*sizeof(type) will give you the answer. If you want
>> the number of value bits, then you can figure it out from the
>> type's range, although the calculation for that is not as simple.

>
> In other words my question is this. Does C95 specify that long must be
> at least 32 bits, or it only provides the minimum value ranges?


In C95 (or C89/C90), just as in C99, the predefined integral types are
defined in terms of their minimal ranges. The range of long is at
least -2147483647 .. +2147483647, which implies that it must have a
least 32 bits (1 sign bit and at least 31 value bits). I don't think
C95 uses the concepts of "value bits" and "padding bits"; those were
introduced by C99.

--
Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      03-09-2008
jacob navia <(E-Mail Removed)> writes:
> Ioannis Vranos wrote:
>> About C95.
>>
>> Is there any mentioning in the standard about the number of usable
>> bits of the various built in types, apart from char/signed
>> char/unsigned char types? Or only about the minimum value ranges of
>> them?

>
> 1) C95 is not a standard. It is obsoleted by C99.


It is still a de facto standard, far more widely implemented than C99.

This attitude is amusing coming from someone whose own compiler
doesn't fully implement the C99 standard.

> 2) Use C99 int32_t, int64_t, etc


How does that answer his question? He was asking how the standard
defines the built-in types, not how to obtain a type with a specified
number of bits. And of course int32_t and int64_t are, at least in
principle, not portable; if the implementation doesn't happen to
provide type of exactly 32 or 64 bits with a 2's-complement
representation and no padding bits, they won't exist.

--
Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Barry Schwarz
Guest
Posts: n/a
 
      03-09-2008
On Sun, 09 Mar 2008 01:58:54 +0200, Ioannis Vranos
<(E-Mail Removed)> wrote:

>About C95.
>
>Is there any mentioning in the standard about the number of usable bits
>of the various built in types, apart from char/signed char/unsigned char
>types? Or only about the minimum value ranges of them?


For integer types you can compute the minimum number of usable bits
from the ranges. For floating point types, you can compute the
minimum number of usable bits from the minimum number of significant
digits in each type.


Remove del for email
 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      03-09-2008
Ioannis Vranos wrote:

> jacob navia wrote:
>> Ioannis Vranos wrote:
>>> About C95.
>>>
>>> Is there any mentioning in the standard about the number of usable
>>> bits of the various built in types, apart from char/signed
>>> char/unsigned char types? Or only about the minimum value ranges of
>>> them?

>>
>> 1) C95 is not a standard.

>
>
> What do you mean it isn't a standard? Of course it is.


Techinally the current C Standard is ISO 9899:1999, also called C99.

However, in practise, C95 (the Standard ISO:9899:1989 + Amendment 1) is
more widely implemented and used.

>> It is obsoleted by C99.
>>
>> 2) Use C99 int32_t, int64_t, etc

>
> I want to program in C95.


Perfectly fine.

Coming to your question, the Standard actually defines the fundamental
types in terms of their range, i.e., a signed char must hold values
from -127 to 127, an unsigned long must hold values from 0 to
4294967295 and so on. These details can be found in section 5.2.4.2 of
the Standard.

Only the types intN_t and uintN_t for values of N 8, 16, 32, and 64 are
more rigorously defined. They must be exactly of that size (in bits)
and must be represented in twos complement and must not have padding
bits. But they are not relevant to you, as you are focused on C95.

Although you can find out the number of usable (i.e. value) bits from
the range of a type, it's not easy and even then there is no
information on particular bits. For example bits 2 to 4 may be padding
bits, or may not be, you can't easily tell.

 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      03-09-2008
Ioannis Vranos said:

> jacob navia wrote:
>> Ioannis Vranos wrote:
>>> About C95.
>>>
>>> Is there any mentioning in the standard about the number of usable
>>> bits of the various built in types, apart from char/signed
>>> char/unsigned char types? Or only about the minimum value ranges of
>>> them?

>>
>> 1) C95 is not a standard.

>
>
> What do you mean it isn't a standard? Of course it is.


Right.

Do you remember your first foray into comp.lang.c a few years ago? Remember
when you knew all the answers, and anyone that disagreed with you must be
some kind of idiot? Well, you learned better. Jacob Navia didn't.

>> It is obsoleted by C99.
>>
>> 2) Use C99 int32_t, int64_t, etc

>
>
> I want to program in C95.


I want to program in C, which for me means sticking to the common subset of
C90, C95, and C99. It is true that the current de jure standard is C99,
but until, at the very least, GNU and Microsoft offer conforming C99
implementations it will not be a de facto standard in the foreseeable
future. Note that lcc-win32, which Jacob Navia pushes even harder than he
pushes C99, is not C99-conforming.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
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
Minimum and Maximum of a list containing floating point numbers ceycey Python 5 09-07-2010 02:52 PM
Minimum value of floating point types. Fred Zwarts C++ 5 10-08-2009 03:46 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C Programming 45 11-04-2008 12:39 PM
Minimum sizes of integral and floating point types Ioannis Vranos C++ 13 03-10-2008 06:29 PM



Advertisments