This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: C Integers
- From: Andrew Haley <aph at redhat dot com>
- To: JimJoyce <jim at jimjoyce dot co dot uk>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 06 May 2013 16:04:43 +0100
- Subject: Re: C Integers
- References: <1367838699972-935964 dot post at n5 dot nabble dot com>
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.