int and float memory space

Discussion in 'C Programming' started by alok, Mar 21, 2011.

  1. alok

    alok Guest

    Why bytes needed by int and float is machine dependent?
    alok, Mar 21, 2011
    #1
    1. Advertising

  2. alok

    alok Guest

    On Mar 21, 11:43 pm, "Scott Fluhrer" <> wrote:
    > "alok" <> wrote in message
    >
    > news:...
    >
    > > Why bytes needed by int and float is machine dependent?

    >
    > Because machines vary on the sizes of integers and floating point values
    > (and, for that matter, the size of a 'byte') that they work most efficiently
    > with.  For example, some smaller CPUs can work efficiently with 16 bit
    > values; anything larger than that is a pain.  On the other extreme, some
    > CPUs work most efficiently with 32 or 64 bit values, and convincing them to
    > work with smaller integers would actually slow things down.
    >
    > Now, C could preselect a specific size (and insist that all implementations
    > do whatever conversion is necessary to make that specific size work);
    > however, C has a bias towards efficiency, and so it lets the implementation
    > pick what's efficient (as long as it meets various minimums, for example,a
    > variable of type 'int' must be able to represent any value between -32767
    > and 32767).
    >
    > --
    > poncho


    Poncho,

    So if the machine size is 32 bit the integer size will be 32 bit?

    thanks for your wonderful reply.
    alok, Mar 22, 2011
    #2
    1. Advertising

  3. "Scott Fluhrer" <> writes:
    > "alok" <> wrote in message
    > news:...
    > On Mar 21, 11:43 pm, "Scott Fluhrer" <> wrote:
    >> So if the machine size is 32 bit the integer size will be 32 bit?

    >
    > Perhaps, and perhaps not. That's really the compiler writer's call. The
    > intent in the design of C is that common C types be efficient, but there's
    > really nothing enforcing it.


    And in practice, it's very common to choose sizes based on compatibility
    with other systems. For example, if a 32-bit system is a direct
    descendant of a similar 16-bit system, the implementer might well choose
    to make int 16 bits so that code written for the older system will work
    without change.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Mar 22, 2011
    #3
    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. Schnoffos
    Replies:
    2
    Views:
    1,189
    Martien Verbruggen
    Jun 27, 2003
  2. bd
    Replies:
    0
    Views:
    597
  3. Nick Coghlan
    Replies:
    0
    Views:
    463
    Nick Coghlan
    Dec 6, 2004
  4. k3n3dy
    Replies:
    15
    Views:
    969
    dan2online
    Apr 20, 2006
  5. Carsten Fuchs
    Replies:
    45
    Views:
    1,486
    James Kanze
    Oct 8, 2009
Loading...

Share This Page