Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Long vs INT variables 2

Status
Not open for further replies.

NTesla

Programmer
Jul 19, 2002
146
US
What is the differance betweent long and int variables
 
What is the range of each? How many bits can each hold?
 
The range of a long is –2,147,483,648 to 2,147,483,647 and is 4 bytes. An integer is system dependant and can be equal to or shorter than the size of a long. I suppose under some circumstances they could be the same, except a long will give more predictable results when being placed on different computers.

-Bones
 
for 32bit compillers is no range difference. But type are different. By default if you do a

x = 1234;

the 1234 is considered as int. When you overload operator = to long and do an = with a 1234 you will get compiller error if you don't have an operator = (int...).

Ion Filipski
1c.bmp
 
By standard, long is always 32-bits!

Int can have any size, it's machine-dependantbut, but nowadays on a PC is usually also 32-bits.
 
long could be 64bit in the future, that's why the keyword "long" exist. It is for forward compatibility. Maybe size of long will not change in the future, but maybe yes.

Ion Filipski
1c.bmp
 
IEEE standard is 32 bits, some computing groups in Japan refuse to conform to IEEE standard. Also, on CRAY supercomputers a word is 64 bits. It is possible that in the forseeable future, home computing may advance to 64bits per word.

 
> By standard, long is always 32-bits!
C99 states that a long should be at LEAST 32 bits, it is not limited to be exactly 32 bits.
Since C++ has <climits> (which is called limits.h in C), I would say that C++ follows the same rules for determining the limits on the ranges of data types.

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top