[Courses] [C Programming] Anyone still here?
James
jas at spamcop.net
Fri May 24 15:57:40 EST 2002
On 25 May 2002, Jenn Vesperman wrote:
> With the math variable types:
>
> A short is sometimes longer than an int, but never longer than a long.
> An int is the width of the data bus.
> A long is as many bytes as the CPU registers can handle in a single
> operation.
>
> Note that these lengths are NOT guaranteed. Fun, huh?
>
>
> In practice:
>
> A short is 16 or 32 bits
> An int is 32 bits
> A long is 32 bits (and rarely used)
> A double is often 32 bits, as well
>
> A float is 16 bits,
32 on x86, while a double is 64 and a long double is 96...
> but because within the 16 bits is the exponent, it
> usually only has about five places of precision.
Here's a list of sizes of each type, in bytes:
int: 4
long: 4
short: 2
short int: 2
long int: 4
long long int: 8
float: 4
double: 8
long double: 12
void *: 4
This is on x86, which is a "32 bit machine" at heart. This means almost
everything is 32 bits, unless you override it with "short" or "long long".
It's actually the compiler, rather than the CPU, which determines this; on
64 bit machines like MIPS, you can often CHOOSE which size ints are...
You need to be careful of this in some cases: if you're doing file access,
using an "int" to store the offset limits you to 2 Gbyte files. To get
around this, you can compile with a special #define directive, and use 64
bit variants instead.
On 64 bit machines, I think almost everything becomes 64 bits, depending
on the compiler's settings, but haven't got one to experiment on... :-)
James.
More information about the Courses
mailing list