Why bytes needed by int and float is machine dependent?
|
|
0
|
|
|
|
Reply
|
manglikalok (3)
|
3/21/2011 6:16:41 PM |
|
"alok" <manglikalok@gmail.com> wrote in message
news:17bf789c-4d85-4903-9710-e30e27f5de0c@34g2000pru.googlegroups.com...
> 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
|
|
0
|
|
|
|
Reply
|
Scott
|
3/21/2011 6:43:06 PM
|
|
On Mar 21, 11:43=A0pm, "Scott Fluhrer" <sfluh...@ix.netcom.com> wrote:
> "alok" <manglika...@gmail.com> wrote in message
>
> news:17bf789c-4d85-4903-9710-e30e27f5de0c@34g2000pru.googlegroups.com...
>
> > 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 efficien=
tly
> with. =A0For example, some smaller CPUs can work efficiently with 16 bit
> values; anything larger than that is a pain. =A0On the other extreme, som=
e
> 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 implementatio=
ns
> do whatever conversion is necessary to make that specific size work);
> however, C has a bias towards efficiency, and so it lets the implementati=
on
> 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.
|
|
0
|
|
|
|
Reply
|
alok
|
3/22/2011 5:58:55 PM
|
|
"alok" <manglikalok@gmail.com> wrote in message
news:10ede842-169f-4989-b319-375e89610026@a21g2000prj.googlegroups.com...
On Mar 21, 11:43 pm, "Scott Fluhrer" <sfluh...@ix.netcom.com> wrote:
> Poncho,
>
> 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.
--
poncho
|
|
0
|
|
|
|
Reply
|
Scott
|
3/22/2011 6:06:37 PM
|
|
"Scott Fluhrer" <sfluhrer@ix.netcom.com> writes:
> "alok" <manglikalok@gmail.com> wrote in message
> news:10ede842-169f-4989-b319-375e89610026@a21g2000prj.googlegroups.com...
> On Mar 21, 11:43 pm, "Scott Fluhrer" <sfluh...@ix.netcom.com> 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) kst-u@mib.org <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"
|
|
0
|
|
|
|
Reply
|
Keith
|
3/22/2011 6:26:51 PM
|
|
On 3/22/2011 1:58 PM, alok wrote:
> [...]
> So if the machine size is 32 bit the integer size will be 32 bit?
What is "machine size?" I think that if you try to formulate
a precise definition, you will see that the answer leads nowhere
useful. Useful from a hardware designer's point of view, yes, but
not very useful to a software programmer.
Scott Fluhrer's explanation (paraphrase: "Different machines
are different") is pretty much the story. Somebody designing a C
implementation considers the CPU's instruction set, possibly mixes
in some information about the CPU hardware and characteristics of
other system components, speculates about market forces, and makes
a choice: "We will use a 28-bit int, and That's That." As C
programmers, we look at the resulting implementation and say "Oh,
28-bit ints, ugh, I want a different system" or "Hooray! 28-bit
ints, just what I've wanted all these years!" or something in
between. And we "vote with our feet" on whether the implementor's
choice was a good one (for us) or not.
The point is this: The implementor has the freedom to make
that choice, a freedom he would not have if he were implementing
Java, say. Java says "An int is 32 bits, whether that's convenient
or not" and hands the implementor the burden of dealing with the
fiat. This is nice in one way, because the Java programmer doesn't
need to worry about the sizes and ranges of primitives the way the
C programmer does. But at the same time, it means the programmer
has no way to say "I want an integer of modest size that the system
can handle with maximal ease," which is what a C programmer gets
by writing `int'.
--
Eric Sosman
esosman@ieee-dot-org.invalid
|
|
0
|
|
|
|
Reply
|
Eric
|
3/23/2011 2:11:16 AM
|
|
|
5 Replies
285 Views
(page loaded in 0.067 seconds)
Similiar Articles: Is union really useful in C++ considering that there is ...When you may use the same storage to store potentially ... answer is that unions were designed to safe space ... enum type { int_, char_, char_pointer, float_ } int type ... FPC: A High-Speed Compressor for Double-Precision Floating-Point ...... quality-analisis in pulse- or frequency-space ... that interpreting a (positive) IEEE floating point number as integer (i.e ... between processing nodes and with mass storage ... Neatest way to get the end pointer? - comp.lang.cFor example: int my_array[X]; int *p = my ... most_ one byte) is reserved at the end of the memory space. ... floating point library (if there is a seperate floating ... Difference between passing a number and a variable to a subroutine ...Rank of the dataset in memory INTEGER :: i, j ... mem_space_id_default INTEGER(HID_T) :: file_space ... number, so to a ieee-754 64 bit floating ... How to check whether malloc has allocated memory properly in case ...(Keep in mind that `int' and `size_t' are not ... consumes some resources, at least address space if not actual memory. ... mapped these declarations to the 60-bit floating ... counting the digits in a number, exponential format problem - comp ...... manual/en/language.types.string.php#language.types.string.casting "An integer or float is ... adding an exponent will always increase the space taken by the space used by ... FBO and glReadPixels slowness - comp.graphics.api.opengl ...... static GLenum TEX_TYPE = GL_TEXTURE_2D; int tSize ... RGB_FLOAT32_ATI, tSize, tSize, 0, GL_RGB, GL_FLOAT,0 ... Reading rendered image into memory - comp.graphics.api ... input & output in assembly - comp.lang.asm.x86... format it is in (ASCII numbers? packed BCD numbers? signed 32-bit integer? 80-bit floating ... are effectively mixing code and data, since there is only one huge memory space ... variant data type - comp.lang.fortran... LONGLONG *pllVal; FLOAT *pfltVal ... ULONGLONG ullVal; INT intVal ... that there is ..... things (variants) in same memory space is ... How to generate random number without replacement? - comp.lang ...It seems that the int(rand(10)) generate random with ... already has Bit_On($index) and bit_test($index) so memory ... the bit-vector scheme, but taking up FAR FAR more space. ? Data Types, their Format and Space - Binary Sneeze | The mind is a ...int Integer. float ... Space: The float type data takes four bytes in the memory and it can store real values from 3.4×10-38 to 3 ... Primary Data Types,Memory Occupied By Integer in C,C Floating ...Primary Data Types : 1. Integer Data Type : Integers are whole numbers with a range of values, Generally an integer occupies 2 bytes memory space and its value range ... 7/25/2012 9:24:20 PM
|