Minimum sizes of integral and floating point types

Discussion in 'C Programming' started by Ioannis Vranos, Mar 8, 2008.

  1. 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?
    Ioannis Vranos, Mar 8, 2008
    #1
    1. Advertising

  2. Ioannis Vranos

    jacob navia Guest

    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
    jacob navia, Mar 9, 2008
    #2
    1. Advertising

  3. 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.
    Ioannis Vranos, Mar 9, 2008
    #3
  4. Ioannis Vranos

    Ben Pfaff Guest

    Ioannis Vranos <> 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,0xa67f6aaa,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 1:putchar(a[i&15]);break;}}}
    Ben Pfaff, Mar 9, 2008
    #4
  5. Ben Pfaff wrote:
    > Ioannis Vranos <> 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?
    Ioannis Vranos, Mar 9, 2008
    #5
  6. Ioannis Vranos <> writes:
    > Ben Pfaff wrote:
    >> Ioannis Vranos <> 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) <>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Mar 9, 2008
    #6
  7. jacob navia <> 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) <>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Mar 9, 2008
    #7
  8. On Sun, 09 Mar 2008 01:58:54 +0200, 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?


    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
    Barry Schwarz, Mar 9, 2008
    #8
  9. Ioannis Vranos

    santosh Guest

    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.
    santosh, Mar 9, 2008
    #9
  10. 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
    Richard Heathfield, Mar 9, 2008
    #10
    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. Ioannis Vranos
    Replies:
    13
    Views:
    467
    James Kanze
    Mar 10, 2008
  2. Fred Zwarts
    Replies:
    5
    Views:
    769
    puzzlecracker
    Oct 8, 2009
  3. ceycey
    Replies:
    5
    Views:
    503
  4. Saraswati lakki
    Replies:
    0
    Views:
    1,275
    Saraswati lakki
    Jan 6, 2012
  5. Marco
    Replies:
    2
    Views:
    88
    Serhiy Storchaka
    Jul 16, 2013
Loading...

Share This Page