Page 1 of 1

int Vs long

Posted: Sun Aug 15, 2004 10:44 pm
by Guest
Hi all,
What is the difference between int and long in 32-bit compilers. Both occupies 4 bytes of memory. Then, what might be difference between those two types?

Thanks in advance

Re:int Vs long

Posted: Mon Aug 16, 2004 12:33 am
by Neo
'long' and 'short' are only qualifiers to the 'int' datatype. They have no fixed sizes only 'compiler' chosen sizes.
'int' will normally be the natural size of the machine and 'short' is 16 bits usually. Most of the time 'short' is 16 bits 'long' 32 bits and 'int' 16 or 32 bits. The compiler is free to choose the appropriate size where 'short' is never longer than 'int' and 'int' never longer than a 'long'.
So in your case (a 32 bit compiler) 'int' and 'long' refer to the same thing. VC++ and GCC both use 32 bits for 'int' and 'long'.
I guess in the days of 16 bit compilers the difference was significant (in terms of implementation) but now it seems to have blurred out.
BTW anyone who can tell me their sizes on a 64 bit compiler. Are they the same?

Re:int Vs long

Posted: Mon Aug 16, 2004 4:06 am
by Candy
Neo wrote: BTW anyone who can tell me their sizes on a 64 bit compiler. Are they the same?
short int -> 16
int -> 32
long int -> 64
long long -> 64

for 32-bit:
short int -> 16
int -> 32
long int -> 32
long long -> 64

Re:int Vs long

Posted: Mon Aug 16, 2004 3:12 pm
by Arto
Remember that it can also change based on the platform and the compiler used; so what was mentioned above may be true in a majority of cases but certainly not in all. Therefore it's best to check the documentation for the particular compiler and architecture you're using.

Some more info with regards to the GNU compiler.