Size of data types in C?

Discussion in 'C Programming' started by siliconwafer, Oct 10, 2005.

  1. siliconwafer

    siliconwafer Guest

    Who decides size of data types in C?
    Is it the:
    1.C standard and hence the compilers
    2.Operating System.
    siliconwafer, Oct 10, 2005
    #1
    1. Advertising

  2. In article <>,
    siliconwafer <> wrote:

    >Who decides size of data types in C?
    >Is it the:
    >1.C standard and hence the compilers
    >2.Operating System.


    Both, or rather all three.

    The standard places constraints on the minimum size of several types.
    The compiler can use any sizes it likes that meet these constraints,
    but in order to interoperate with the operating system's libraries and
    meet the expectations of users any successful compiler will have to
    take the operating system into account.

    Nothing stops you writing a C compiler for Linux that provides 17-bit
    ints and 18 bit pointers, but you won't sell many.

    -- Richard
    Richard Tobin, Oct 10, 2005
    #2
    1. Advertising

  3. siliconwafer

    Guest

    what about the Hardware...Doesn't it maily rely on that...?

    coz if the H/w is capable then only...the implementation is useful...?

    right..?
    , Oct 10, 2005
    #3
  4. siliconwafer

    siliconwafer Guest

    wrote:
    > what about the Hardware...Doesn't it maily rely on that...?
    >
    > coz if the H/w is capable then only...the implementation is useful...?
    >
    > right..?

    Which H/W *exactly* decides this?Is it the data width of memory where
    the compiler stores the variables? OR is it the CPU regesters?
    siliconwafer, Oct 10, 2005
    #4
  5. (Richard Tobin) writes:
    [...]
    > Nothing stops you writing a C compiler for Linux that provides 17-bit
    > ints and 18 bit pointers, but you won't sell many.


    If by "17-bit ints" you mean, say, 18-bit ints with 1 padding bit,
    that's true, as long as CHAR_BIT is either 9 or 18.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Oct 10, 2005
    #5
  6. [OT] Re: Size of data types in C?

    In article <>,
    Keith Thompson <> wrote:
    > (Richard Tobin) writes:


    >> Nothing stops you writing a C compiler for Linux that provides 17-bit
    >> ints and 18 bit pointers, but you won't sell many.


    >If by "17-bit ints" you mean, say, 18-bit ints with 1 padding bit,
    >that's true, as long as CHAR_BIT is either 9 or 18.


    But it's *Linux*, so you aren't going to -sell- many of *anything*
    (discounting the "Linux for Dummies" books and the Slashdot
    merchandise.)


    Some of my co-workers are modelling the spread of infectious diseases.
    (Seriously so.) As best I can tell, the same techniques can be
    used to model the spread of Linux.
    Walter Roberson, Oct 10, 2005
    #6
  7. In article <>,
    Keith Thompson <> wrote:

    >> Nothing stops you writing a C compiler for Linux that provides 17-bit
    >> ints and 18 bit pointers, but you won't sell many.


    >If by "17-bit ints" you mean, say, 18-bit ints with 1 padding bit,
    >that's true, as long as CHAR_BIT is either 9 or 18.


    Much more likely is that CHAR_BIT is 17 and pointers have 16 padding
    bits :)

    -- Richard
    Richard Tobin, Oct 10, 2005
    #7
  8. siliconwafer

    Netocrat Guest

    Re: [OT] Re: Size of data types in C?

    On Mon, 10 Oct 2005 19:43:35 +0000, Walter Roberson wrote:

    > Some of my co-workers are modelling the spread of infectious diseases.
    > (Seriously so.) As best I can tell, the same techniques can be used to
    > model the spread of Linux.


    So Microsoft were right - the GPL _is_ viral!

    --
    http://members.dodo.com.au/~netocrat
    Netocrat, Oct 10, 2005
    #8
  9. siliconwafer

    siliconwafer Guest

    "what about the Hardware...Doesn't it maily rely on that...? "


    Which H/W *exactly* decides this?Is it the data width of memory where
    the compiler stores the variables? OR is it the CPU regesters?

    Reply
    MyAnswer?
    siliconwafer, Oct 11, 2005
    #9
  10. In article <>,
    siliconwafer <> wrote:
    >"what about the Hardware...Doesn't it maily rely on that...? "


    >Which H/W *exactly* decides this?Is it the data width of memory where
    >the compiler stores the variables? OR is it the CPU regesters?


    >Reply
    >MyAnswer?


    Oh, I thought your question was rhetorical.

    For the same hardware and the same OS, there might be several
    compiler options that lead to different type sizes. Not all
    of those are necessarily going to be implemented as pure hardware
    operations. A 128 bit "long long" on a machine with 64 bit
    registers might be processed through library calls or through
    standard multi-precision techniques for simpler operations.

    Integral type sizes chosen for a particular combination of
    hardware + OS + compiler + flags
    will -usually- involve a power-of-2 multiplied by the native
    operation size, as those sizes are usualy easier to program.

    Floating point type sizes, if not using the native size, are
    more likely to be reliant on the politics of whatever the IEEE
    committee has defined.

    In any case, operation sizes supported will be strongly
    influenced by marketting considerations. If your potential
    customer is the National Weather Office, and they tell you
    they want a 240 bit float synthesized from three 80-bit registers,
    and they say, "We have $47 million for this project if you can
    install 3 of them before the next hurricane season", then
    you answer "Yes, certainly", not "But our longest hardware
    register is only 64 bits."
    --
    "It is important to remember that when it comes to law, computers
    never make copies, only human beings make copies. Computers are given
    commands, not permission. Only people can be given permission."
    -- Brad Templeton
    Walter Roberson, Oct 11, 2005
    #10
  11. siliconwafer

    Guest

    hi,
    It is basicaly decided by the compiler.
    OS simply provide the base for the compiler and nothing else . But it
    is mutual because if OS is not capable enough to handle the request of
    compiler then it is not possible for compiler to get done any work.
    For example turbo C takes only two bytes in case of int while VC++
    takes 4 byte fopr the same int.
    Or take one more example of java for the same platform turbo C
    allocate only two byte while java allocate 4 bytes.
    , Oct 11, 2005
    #11
  12. siliconwafer a écrit :
    > Who decides size of data types in C?
    > Is it the:
    > 1.C standard and hence the compilers
    > 2.Operating System.
    >


    It's more subtle...

    - The C-standard doen't define the data types i terms of width but
    rather in terms of range. It gives minimum ranges for each type :

    Type Minimum Maximum
    char 0 127
    unsigned char 0 255
    signed char -127 127
    [signed] short -32767 32767
    usigned short 0 65535
    [signed] int -32767 32767
    unsigned [int] 0 65535
    [signed] long [int] -2147483647 2147483647
    unsigned long [int] 0 4294967295

    [fixed font required]

    - The implementation (the processor and the way it is used by the
    system) fixes the actual number of bits of each type, so that the
    minimum C-requirements are reached.

    For example:

    x86 real and extended mode (BIOS, MS-DOS, Windows 3x):

    char is 8-bit
    short is 16-bit
    int is 16-bit
    long is 32-bit

    Same processor but in protected mode (aka '32-bit') as used by Win32,
    Linux etc.:

    char is 8-bit
    short is 16-bit
    int is 32-bit
    long is 32-bit

    Now, if you play with a Texas Instrument DSP like TMS320C54:

    char is 16-bit
    short is 16-bit
    int is 16-bit
    long is 32-bit

    etc. It depends on the hardware capabilities.
    Emmanuel Delahaye, Oct 11, 2005
    #12
  13. Walter Roberson wrote:
    > In article <>,
    > Keith Thompson <> wrote:
    > > (Richard Tobin) writes:

    >
    > >> Nothing stops you writing a C compiler for Linux that provides 17-bit
    > >> ints and 18 bit pointers, but you won't sell many.

    >
    > >If by "17-bit ints" you mean, say, 18-bit ints with 1 padding bit,
    > >that's true, as long as CHAR_BIT is either 9 or 18.

    >
    > But it's *Linux*, so you aren't going to -sell- many of *anything*
    > (discounting the "Linux for Dummies" books and the Slashdot
    > merchandise.)


    Arguable.

    > Some of my co-workers are modelling the spread of infectious diseases.
    > (Seriously so.) As best I can tell, the same techniques can be
    > used to model the spread of Linux.


    Or the spread of technological innovations (movile phones, digital
    cameras...), or the spread of nenufars in a lake, or the growth rate of
    a bacteria population, or the spread of hoaxes over email users, or the
    spread of ...

    The logistical equation can be applied in many many situations.
    Antonio Contreras, Oct 11, 2005
    #13
    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. Sunil

    On what does size of data types depend?

    Sunil, Oct 5, 2005, in forum: C Programming
    Replies:
    35
    Views:
    1,307
    Anonymous 7843
    Oct 12, 2005
  2. ramu
    Replies:
    2
    Views:
    322
    rlblaster
    Feb 20, 2006
  3. Jason Cavett

    Preferred Size, Minimum Size, Size

    Jason Cavett, May 23, 2008, in forum: Java
    Replies:
    5
    Views:
    12,556
    Michael Jung
    May 25, 2008
  4. Gary Roach
    Replies:
    0
    Views:
    111
    Gary Roach
    Sep 1, 2013
  5. Fábio Santos
    Replies:
    0
    Views:
    120
    Fábio Santos
    Sep 4, 2013
Loading...

Share This Page