[vox-tech] Size of long int?

Chanoch (Ken) Bloom kbloom at gmail.com
Sat Jan 9 16:33:21 PST 2010


On Fri, 2010-01-08 at 23:00 -0800, Brian Lavender wrote:
> It seems that long int on 32 bit is 4 bytes on my 32 bit machines with
> gcc and on my 64 bit machine is 8 bytes.
> 
> There is no standard on long int, is there? 
> 
> #include <stdio.h>
> 
> int main()
> {
>    printf("Size of int is %ld\n",sizeof(long int));
>    return 0;
> }
> 
> 
> brian

We had a presentation about the AMD64 at LUGOD (in 1131 EUII as I
recall) when it was first coming out, and this was one of the points
they mentioned.

Typically, char is 8 bits, short is 16, and long are 32, and int is the
machine word size, though no standard guarantees any of this.
On x86 they made int 32bits wide for that reason.

On AMD64, they kept the normal int at 32 bits wide, and widened the long
to 64bits. 

If you need exact-sized types, look in <stdint.h>, which defines
int8_t, int16_t, int32_t, int64_t,
uint8_t, uint16_t, uint32_t, uint64_t,
and other potentially useful variations (int_least#_t, and int_fast#_t)
that guarantee exact sizes, or minimum sizes (not to mention lots of
#defines for the limits)


More information about the vox-tech mailing list