[Courses] [C] Why so many types? (Re: Current topic: variables in C.)
Mary
linuxchix at puzzling.org
Sun Jun 9 16:20:59 EST 2002
On Sun, Jun 09, 2002 at 02:02:56AM -0400, Charlotte Oliver wrote:
> On Sat, Jun 08, 2002 at 11:36:14PM -0600, Val Henson wrote:
> > Oo, here's a good question:
> >
> > "Why does C have this nasty int, char, long stuff? Why didn't they
> > just say 8_bit_type and 16_bit_type instead of all these complicated
> > rules about int being at least 2 bytes but less than or equal to long,
> > etc., etc., etc.?"
> >
> > If anyone is interested, pipe up.
>
> Sure! Why didn't they just make them more simplistic, or does that
> have to do with features being added over time?
OK, here's a small summary, others may want to contribute more:
This summary should be understanbable by anyone who has played with the
basic C types: int, char, float and so on...
The basic model of a computer processer is that values are loaded from
memory into registers, which are pieces of memory directly accessible to
the CPU. The CPU can not manipulate values from memory, it can only
access the registers.
There are a very small number of registers, somewhere in the range of
ten to fifty depending on your processor model (and they're much faster
to access than RAM too). There are two types of register for storing
data - integer registers, and floating point registers.
The reason for this is that there are some differences between
performing arithmetic on integer (whole number) data and floating point
(real number data, stored to a limited number of significant figures)
arithmetic and the processer does integer arithmetic differently from
floating point arithmetic. So C makes this distinction too.
Now, different processors have different size registers. Some have 16
bit registers (they can store 2^16 different numbers), some have 32 bit
registers (they can store 2^32 different numbers) and some have 64 bits,
or 8 bits. This is why C integers are not meant to be a specific size.
OK, that's a small summary. I'm not familiar with floating point stuff
much, so someone else may want to explain why we have floats and
doubles, and how big they are.
-Mary.
More information about the Courses
mailing list