who decides the size of a data type?

Discussion in 'C Programming' started by rao, Mar 16, 2008.

  1. rao

    rao Guest

    On some of the compilers integer size is 2 and on some other it is 4
    bytes.
    My doubt is who decides the size of the integer?
    is it plainly the compiler?
    Does OS or Processor also has any control in deciding the size of such
    data types?
     
    rao, Mar 16, 2008
    #1
    1. Advertising

  2. rao

    Willem Guest

    rao wrote:
    ) On some of the compilers integer size is 2 and on some other it is 4
    ) bytes.

    And on some, it is 8. And on very few others, it's another number.

    ) My doubt is who decides the size of the integer?

    In India, do 'doubt' and 'question' translate to the same word ?
    In any case, the right word to use in English is 'question'.

    ) is it plainly the compiler?
    ) Does OS or Processor also has any control in deciding the size of such
    ) data types?

    Usually, the compiler decides the size, based on what the OS and/or
    the processor have to offer. I think the C standard even strongly
    suggests that 'int' be the size that is 'most natural' to the system.

    However, it is ultimately the compiler that makes the decision.
    For example, there are systems that have 'natural' 8-byte integers,
    but a lot of C compilers still use 4-byte int types.


    SaSW, Willem
    --
    Disclaimer: I am in no way responsible for any of the statements
    made in the above text. For all I know I might be
    drugged or something..
    No I'm not paranoid. You all think I'm paranoid, don't you !
    #EOT
     
    Willem, Mar 16, 2008
    #2
    1. Advertising

  3. >On some of the compilers integer size is 2 and on some other it is 4
    >bytes.


    There are other possibilities. Don't be surprised to see 8 in the
    future. And 3 isn't impossible.

    >My doubt is who decides the size of the integer?


    The compiler writer. But some choices make his job easier than others.

    >is it plainly the compiler?
    >Does OS or Processor also has any control in deciding the size of such
    >data types?


    The choice is heavily influenced by such things as the size of
    machine registers, the instruction set of the machine, and the
    interface the OS provides. It is possible, for example, to provide
    an integer of size 3 (3 11-bit characters) on an Intel x86 machine,
    but the code will not be very efficient and it may be wasteful of
    storage. You can emulate one machine on another, and generate code
    for the emulated machine, but that's a lot of effort and no guarantee
    of efficiency.
     
    Gordon Burditt, Mar 16, 2008
    #3
  4. rao

    santosh Guest

    rao wrote:

    > On some of the compilers integer size is 2 and on some other it is 4
    > bytes.
    > My doubt is who decides the size of the integer?
    > is it plainly the compiler?
    > Does OS or Processor also has any control in deciding the size of such
    > data types?


    Generally both. Most compilers map C's numeric types to the underlying
    hardware types in the most efficient manner possible. Usually the type
    char is aliased to the machine's byte while the type int corresponds to
    the native word of the processor. Other types may vary. Main concerns
    for implementors are to avoid breaking existing code and to provide as
    much efficiency as possible.

    The Standard of course specifies the minimum ranges for these types
    which every conforming compiler must adhere to.
     
    santosh, Mar 16, 2008
    #4
  5. rao

    harsha Guest

    On Mar 16, 8:31 pm, Willem <> wrote:
    <snip>
    > In India, do 'doubt' and 'question' translate to the same word ?
    > In any case, the right word to use in English is 'question'.


    When in doubt, we ask a question.
     
    harsha, Mar 16, 2008
    #5
  6. santosh wrote:

    > Usually the type char is aliased to the machine's
    > byte while the type int corresponds to the native word of the
    > processor.


    Not to forget that some architectures provide special functions
    to operate on strings, which have some constraints on the type
    (like each element of a string being a byte of 8 bits). It makes
    quite some sense if an C implementation uses this type then for
    char.

    Wolfgang Draxinger
    --
    E-Mail address works, Jabber: , ICQ: 134682867
     
    Wolfgang Draxinger, Mar 16, 2008
    #6
  7. rao

    Ian Collins Guest

    Willem wrote:
    >
    > ) is it plainly the compiler?
    > ) Does OS or Processor also has any control in deciding the size of such
    > ) data types?
    >
    > Usually, the compiler decides the size, based on what the OS and/or
    > the processor have to offer. I think the C standard even strongly
    > suggests that 'int' be the size that is 'most natural' to the system.
    >

    On a hosted environment, the OS dictates the size. In order to work
    with the system's headers and libraries, compilers have to follow the
    platform's standards.

    --
    Ian Collins.
     
    Ian Collins, Mar 16, 2008
    #7
  8. rao

    Lew Pitcher Guest

    Ian Collins wrote:

    > Willem wrote:
    >>
    >> ) is it plainly the compiler?
    >> ) Does OS or Processor also has any control in deciding the size of such
    >> ) data types?
    >>
    >> Usually, the compiler decides the size, based on what the OS and/or
    >> the processor have to offer. I think the C standard even strongly
    >> suggests that 'int' be the size that is 'most natural' to the system.
    >>

    > On a hosted environment, the OS dictates the size. In order to work
    > with the system's headers and libraries, compilers have to follow the
    > platform's standards.


    But this may become a "chicken-and-egg" problem on certain platforms, where
    the OS is easily rebuilt with a conforming C compiler (i.e. recompiling a
    32bit OS into a 64bit OS using a suitable compiler on a 32bit system).
    Additionally, some platforms support multiple concurrent "views" of the
    environment, such that two or more distinct size choices are available at
    execution time (witness some 64bit platforms that execute /either/ 64bit or
    32bit code (with corresponding differences in data type sizes)
    simultaneously).


    --
    Lew Pitcher

    Master Codewright & JOAT-in-training | Registered Linux User #112576
    http://pitcher.digitalfreehold.ca/ | GPG public key available by request
    ---------- Slackware - Because I know what I'm doing. ------
     
    Lew Pitcher, Mar 16, 2008
    #8
  9. Ian Collins <> writes:
    > Willem wrote:
    >> ) is it plainly the compiler?
    >> ) Does OS or Processor also has any control in deciding the size of such
    >> ) data types?
    >>
    >> Usually, the compiler decides the size, based on what the OS and/or
    >> the processor have to offer. I think the C standard even strongly
    >> suggests that 'int' be the size that is 'most natural' to the system.
    >>

    > On a hosted environment, the OS dictates the size. In order to work
    > with the system's headers and libraries, compilers have to follow the
    > platform's standards.


    Typically, yes. But if the headers and libraries are part of the C
    implementation rather than part of the OS, then the C implementation
    can make whatever choices it likes, as long as it's consistent.

    Note, for example, that the MinGW implementation under Windows uses a
    different size and representation for long double than the one the OS
    prefers. This causes problems (since the libraries *are* part of the
    OS, the implementation as a whole is inconsistent), but in theory
    those problems could be solved.

    --
    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 16, 2008
    #9
  10. rao

    Willem Guest

    Lew wrote:
    ) Ian Collins wrote:
    )
    )> Willem wrote:
    )>>
    )>> ) is it plainly the compiler?
    )>> ) Does OS or Processor also has any control in deciding the size of such
    )>> ) data types?
    )>>
    )>> Usually, the compiler decides the size, based on what the OS and/or
    )>> the processor have to offer. I think the C standard even strongly
    )>> suggests that 'int' be the size that is 'most natural' to the system.
    )>>
    )> On a hosted environment, the OS dictates the size. In order to work
    )> with the system's headers and libraries, compilers have to follow the
    )> platform's standards.
    )
    ) But this may become a "chicken-and-egg" problem on certain platforms, where
    ) the OS is easily rebuilt with a conforming C compiler (i.e. recompiling a
    ) 32bit OS into a 64bit OS using a suitable compiler on a 32bit system).
    ) Additionally, some platforms support multiple concurrent "views" of the
    ) environment, such that two or more distinct size choices are available at
    ) execution time (witness some 64bit platforms that execute /either/ 64bit or
    ) 32bit code (with corresponding differences in data type sizes)
    ) simultaneously).

    I think 'the OS' in this case is meant to be the whole package, especially
    the system headers and libraries. However, an OS may supply multiple sets
    of those, possibly with different sizes for int.

    Besides which, a C compiler may come packaged with libraries and system
    headers of its own.

    But, in general, the compiler takes its cue from the OS.


    SaSW, Willem
    --
    Disclaimer: I am in no way responsible for any of the statements
    made in the above text. For all I know I might be
    drugged or something..
    No I'm not paranoid. You all think I'm paranoid, don't you !
    #EOT
     
    Willem, Mar 16, 2008
    #10
  11. Ian Collins said:

    > Willem wrote:
    >>
    >> ) is it plainly the compiler?
    >> ) Does OS or Processor also has any control in deciding the size of such
    >> ) data types?
    >>
    >> Usually, the compiler decides the size, based on what the OS and/or
    >> the processor have to offer. I think the C standard even strongly
    >> suggests that 'int' be the size that is 'most natural' to the system.
    >>

    > On a hosted environment, the OS dictates the size. In order to work
    > with the system's headers and libraries, compilers have to follow the
    > platform's standards.


    I have a machine here on which are installed several implementations. Most
    of these use 32-bit ints, but a couple use 16-bit ints. So is the OS
    dictating 16-bit, or 32-bit?

    --
    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 16, 2008
    #11
  12. rao

    Ian Collins Guest

    Richard Heathfield wrote:
    > Ian Collins said:
    >
    >> Willem wrote:
    >>> ) is it plainly the compiler?
    >>> ) Does OS or Processor also has any control in deciding the size of such
    >>> ) data types?
    >>>
    >>> Usually, the compiler decides the size, based on what the OS and/or
    >>> the processor have to offer. I think the C standard even strongly
    >>> suggests that 'int' be the size that is 'most natural' to the system.
    >>>

    >> On a hosted environment, the OS dictates the size. In order to work
    >> with the system's headers and libraries, compilers have to follow the
    >> platform's standards.

    >
    > I have a machine here on which are installed several implementations. Most
    > of these use 32-bit ints, but a couple use 16-bit ints. So is the OS
    > dictating 16-bit, or 32-bit?
    >

    Whichever is required to use the services of the OS.

    Any implementation is free to provide its own headers and libraries and
    choose its own sizes, but it then restricts its self to building
    applications that do not use any external services provided by the OS.

    --
    Ian Collins.
     
    Ian Collins, Mar 16, 2008
    #12
  13. rao

    Ian Collins Guest

    Lew Pitcher wrote:
    > Ian Collins wrote:
    >
    >> Willem wrote:
    >>> ) is it plainly the compiler?
    >>> ) Does OS or Processor also has any control in deciding the size of such
    >>> ) data types?
    >>>
    >>> Usually, the compiler decides the size, based on what the OS and/or
    >>> the processor have to offer. I think the C standard even strongly
    >>> suggests that 'int' be the size that is 'most natural' to the system.
    >>>

    >> On a hosted environment, the OS dictates the size. In order to work
    >> with the system's headers and libraries, compilers have to follow the
    >> platform's standards.

    >
    > But this may become a "chicken-and-egg" problem on certain platforms, where
    > the OS is easily rebuilt with a conforming C compiler (i.e. recompiling a
    > 32bit OS into a 64bit OS using a suitable compiler on a 32bit system).
    > Additionally, some platforms support multiple concurrent "views" of the
    > environment, such that two or more distinct size choices are available at
    > execution time (witness some 64bit platforms that execute /either/ 64bit or
    > 32bit code (with corresponding differences in data type sizes)
    > simultaneously).
    >

    They do, but they employ standard models for their 32 and 64 bit
    personalities. Providing a compiler for windows that used the LP64
    model or a UNIX compiler that used the LLP64 model would be possible,
    but pointless.

    --
    Ian Collins.
     
    Ian Collins, Mar 16, 2008
    #13
  14. rao

    Ian Collins Guest

    Richard Heathfield wrote:
    > Ian Collins said:
    >
    >> Richard Heathfield wrote:
    >>> Ian Collins said:
    >>>
    >>>> Willem wrote:

    > <snip>
    >>>>> I think the C standard even strongly
    >>>>> suggests that 'int' be the size that is 'most natural' to the system.
    >>>>>
    >>>> On a hosted environment, the OS dictates the size. In order to work
    >>>> with the system's headers and libraries, compilers have to follow the
    >>>> platform's standards.
    >>> I have a machine here on which are installed several implementations.
    >>> Most of these use 32-bit ints, but a couple use 16-bit ints. So is the
    >>> OS dictating 16-bit, or 32-bit?
    >>>

    >> Whichever is required to use the services of the OS.

    >
    > That'd be all of them, then. Hmmm.
    >

    That's fine, as long as they use the platform's 16 or 32 bit model(s).

    --
    Ian Collins.
     
    Ian Collins, Mar 16, 2008
    #14
  15. Ian Collins said:

    > Richard Heathfield wrote:
    >> Ian Collins said:
    >>
    >>> Willem wrote:

    <snip>
    >>>> I think the C standard even strongly
    >>>> suggests that 'int' be the size that is 'most natural' to the system.
    >>>>
    >>> On a hosted environment, the OS dictates the size. In order to work
    >>> with the system's headers and libraries, compilers have to follow the
    >>> platform's standards.

    >>
    >> I have a machine here on which are installed several implementations.
    >> Most of these use 32-bit ints, but a couple use 16-bit ints. So is the
    >> OS dictating 16-bit, or 32-bit?
    >>

    > Whichever is required to use the services of the OS.


    That'd be all of them, then. Hmmm.

    --
    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 16, 2008
    #15
  16. >On a hosted environment, the OS dictates the size. In order to work
    >with the system's headers and libraries, compilers have to follow the
    >platform's standards.


    An OS, especially one not written in C in the first place (this
    applies to the first version of UNIX, too, which was originally
    written in assembly language), may come with *NO* system headers
    (at least not in C) and *NO* C-callable libraries (it might instead
    use assembly-language macros or routines written in some other
    language). In that case, it's up to the C implementor to supply
    those headers (possibly translated from another language) and
    libraries (possibly just "glue" interface routines). If there's
    not a popular C API to the OS, the implementor might have to supply
    one.

    It can still take guidance from the OS (although the more important
    guidance is likely from the CPU architecture). Some systems provide
    several different choices on the same OS, particularly with respect
    to pointer sizes, and provide different sets of libraries for each.
    See, for example, the different MS-DOS memory models, which have
    different combinations of 16-bit and 32-bit data and function
    pointers. I think some compilers also provide a 32-bit mode with
    32-bit ints for MS-DOS. You can't mix compiled or standard code
    from different models (implementations): they all have to come from
    the same one (non-standard features involving the "near" and "far"
    pseudo-keywords made some mixing possible).
     
    Gordon Burditt, Mar 16, 2008
    #16
  17. rao

    Ian Collins Guest

    {I you are going to reply to one of my posts, please stop being so
    arrogant as to ignore attributions]

    Gordon Burditt wrote:
    >> On a hosted environment, the OS dictates the size. In order to work
    >> with the system's headers and libraries, compilers have to follow the
    >> platform's standards.

    >
    > It can still take guidance from the OS (although the more important
    > guidance is likely from the CPU architecture). Some systems provide
    > several different choices on the same OS, particularly with respect
    > to pointer sizes, and provide different sets of libraries for each.
    > See, for example, the different MS-DOS memory models, which have
    > different combinations of 16-bit and 32-bit data and function
    > pointers. I think some compilers also provide a 32-bit mode with
    > 32-bit ints for MS-DOS. You can't mix compiled or standard code
    > from different models (implementations): they all have to come from
    > the same one (non-standard features involving the "near" and "far"
    > pseudo-keywords made some mixing possible).
    >

    Exactly, the compilers follow the OS.

    --
    Ian Collins.
     
    Ian Collins, Mar 16, 2008
    #17
  18. >>> On a hosted environment, the OS dictates the size. In order to work
    >>> with the system's headers and libraries, compilers have to follow the
    >>> platform's standards.

    >>
    >> It can still take guidance from the OS (although the more important
    >> guidance is likely from the CPU architecture). Some systems provide
    >> several different choices on the same OS, particularly with respect
    >> to pointer sizes, and provide different sets of libraries for each.
    >> See, for example, the different MS-DOS memory models, which have
    >> different combinations of 16-bit and 32-bit data and function
    >> pointers. I think some compilers also provide a 32-bit mode with
    >> 32-bit ints for MS-DOS. You can't mix compiled or standard code
    >> from different models (implementations): they all have to come from
    >> the same one (non-standard features involving the "near" and "far"
    >> pseudo-keywords made some mixing possible).
    >>

    >Exactly, the compilers follow the OS.


    MS-DOS did not provide any C system headers or libraries. It's hard to follow
    the OS when the OS doesn't provide direction, which is one reason why so many
    different directions were followed by MS-DOS C compilers.
     
    Gordon Burditt, Mar 16, 2008
    #18
  19. rao

    Ian Collins Guest

    Who said this?

    >>>> On a hosted environment, the OS dictates the size. In order to work
    >>>> with the system's headers and libraries, compilers have to follow the
    >>>> platform's standards.
    >>> It can still take guidance from the OS (although the more important
    >>> guidance is likely from the CPU architecture). Some systems provide
    >>> several different choices on the same OS, particularly with respect
    >>> to pointer sizes, and provide different sets of libraries for each.
    >>> See, for example, the different MS-DOS memory models, which have
    >>> different combinations of 16-bit and 32-bit data and function
    >>> pointers. I think some compilers also provide a 32-bit mode with
    >>> 32-bit ints for MS-DOS. You can't mix compiled or standard code
    >>> from different models (implementations): they all have to come from
    >>> the same one (non-standard features involving the "near" and "far"
    >>> pseudo-keywords made some mixing possible).
    >>>

    >> Exactly, the compilers follow the OS.

    >
    > MS-DOS did not provide any C system headers or libraries. It's hard to follow
    > the OS when the OS doesn't provide direction, which is one reason why so many
    > different directions were followed by MS-DOS C compilers.



    --
    Ian Collins.
     
    Ian Collins, Mar 16, 2008
    #19
  20. rao

    CBFalconer Guest

    Willem wrote:
    > rao wrote:
    >
    >> On some of the compilers integer size is 2 and on some other it
    >> is 4 bytes.

    >
    > And on some, it is 8. And on very few others, it's another number.
    >
    >> My doubt is who decides the size of the integer?

    >
    > In India, do 'doubt' and 'question' translate to the same word ?
    > In any case, the right word to use in English is 'question'.


    No, Willem. The phrases "I have a doubt" and "my doubt" are quite
    ordinary English usage. They are more popular in India than in
    most other English speaking areas. I concede that many native
    English speakers don't recognize that, but their ignorance is of no
    concern. You, apparantly, are Dutch, and have no reason to
    recognize the usage.

    At any rate, apply my favorite exorcism. Sedulously eschew
    obfuscation. :)

    --
    [mail]: Chuck F (cbfalconer at maineline dot net)
    [page]: <http://cbfalconer.home.att.net>
    Try the download section.



    --
    Posted via a free Usenet account from http://www.teranews.com
     
    CBFalconer, Mar 16, 2008
    #20
    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. Replies:
    4
    Views:
    1,545
  2. adelmo

    !! EL EXITO LO DECIDES TU !!!

    adelmo, Dec 14, 2006, in forum: C Programming
    Replies:
    0
    Views:
    514
    adelmo
    Dec 14, 2006
  3. David Basford
    Replies:
    3
    Views:
    2,476
    BootNic
    Sep 30, 2007
  4. Jason Cavett

    Preferred Size, Minimum Size, Size

    Jason Cavett, May 23, 2008, in forum: Java
    Replies:
    5
    Views:
    12,661
    Michael Jung
    May 25, 2008
  5. Bern
    Replies:
    1
    Views:
    82
    Michael Winter
    Oct 13, 2004
Loading...

Share This Page