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
int Vs long
Re:int Vs long
'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?
'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
Re:int Vs long
short int -> 16Neo wrote: BTW anyone who can tell me their sizes on a 64 bit compiler. Are they the same?
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
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.
Some more info with regards to the GNU compiler.