This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C Integers


On 05/06/2013 12:11 PM, 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 ??

Depends.  What is the size of void* ?

> Should C and C++ compilers be re-defining shorts, ints and longs?

No.  It's part of the system ABI.  See

http://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models

Andrew.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]