C Integers
Tim Prince
n8tm@aol.com
Mon May 6 13:01:00 GMT 2013
On 05/06/2013 08:01 AM, Jose-Marcio Martins wrote:
> JimJoyce wrote:
>> When Dennis Ritchie invented the C Programming language, he suggested
>> that a
>> short int would normally occupy 2 bytes, and a long int would take 4
>> bytes,
>> and no matter what the hardware, a long should always be longer than a
>> short. That makes sense.
>> However, he was less precise about the simple int. He simply stated
>> that it
>> should reflect the 'natural' size of the hardware. So it might be like a
>> short on one machine, while like a long on another.
>>
>> Am I 'out of date' and 'out of touch'?
>> Machines and compilers have grown in size since Ritchie's day
>> When I check sizeof(short), sizeof(int) and sizeof(long) on my
>> machine I get
>> 2, 2, 4.
>> Yet my machine is a 64bit one. Is that its 'natural' size. Should not
>> my int
>> be 8 bytes ??
>> Should C and C++ compilers be re-defining shorts, ints and longs?
>
> IMHO, this is an interesting question
>
> Your machine is a "64bit" one ! But you're telling about the processor
> or the operating system ?
>
> Most of the time, when someone say something about choosing between a
> 64 or 32 bits OS, what he has in his mind isn't the wide of the data,
> but the size of the memory address space the OS is able to handle.
>
>
>
There are 64-bit hardware platforms where int is 4 bytes in 32-bit mode,
and 8 bytes in 64-bit mode, becoming less common AFAIK.
More common is a long int of 4 bytes for 32-bit mode, 8 bytes for 64-bit
mode.
Most such platforms have 4-byte pointers in 32-bit mode, 8-byte in
64-bit mode.
8- and 16-bit platforms typically had 2-byte int and pointer, but I
never saw such a thing on a 32- or 64-bit platform.
Do you mean a 16-bit platform with support for 64-bit data types? I did
work on such, 30 years ago, but it didn't have a C compiler.
--
Tim Prince
More information about the Gcc-help
mailing list