int Vs long

Programming, for all ages and all languages.
Post Reply
Guest

int Vs long

Post 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
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:int Vs long

Post 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?
Only Human
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:int Vs long

Post 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
Arto

Re:int Vs long

Post 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.
Post Reply