int on a 64-Bit machine

Hi!
If I declare a variable of type int in C# it will normally map to System.Int32. If I run the same application on a 64-Bit machine will it then map to System.Int64?
[172 byte] By [tommazzo] at [2008-2-27]
# 1

In C#, unlike C++, ints and longs are predefined as being 32 and 64 bit respectively. This is the same on any platform, whether 32 or 64 bit. As long as you aren't using any unmanaged components, you really don't need to worry.

However, I still use Int16/Int32/Int64, etc. instead of int ... I don't believe that int will map to Int32 indefinitely, so I lean towards the side of extra caution.

Josh

JoshLindenmuth at 2007-9-9 > top of Msdn Tech,.NET Development,64-Bit .NET Framework Development....
# 2

int will be always 32-bits. (see 11.11.5 Integral types )

To get a system-dependant 32/64 bits use "native int" (CIL) exposed in class libary as System.IntPtr. For more information read 8.2.2 Built-in Types

TAG at 2007-9-9 > top of Msdn Tech,.NET Development,64-Bit .NET Framework Development....
# 3
In unmanaged C++ int will map to __int64 on a 64-Bit machine right? Wouldn't it be a good idea to change that mapping in .NET some time?
If it were just for some calculations or number storage I wouldn't care, but what about arrays and collections - will they now be using 32-bit or 64-bit indices?
tommazzo at 2007-9-9 > top of Msdn Tech,.NET Development,64-Bit .NET Framework Development....
# 4
Correct - in unmanaged C++ an int is 64 bit on a 64 bit machine with a 64 bit compiler.

The only reason I can see you wanting 64 bits in a managed situation is if you were trying to access over the 4 GB addressable memory limit (for which there are collections such as BigArray), or if you were interfacing with unmanaged code. Otherwise you simply use longs or Int64s in your code.

Josh

JoshLindenmuth at 2007-9-9 > top of Msdn Tech,.NET Development,64-Bit .NET Framework Development....
# 5
Thanks for the heads up. I see that it is not practical to use Int64 indexed arrays in most cases, but just for the sake of completeness, is there any official BigArray implementation for .NET?
tommazzo at 2007-9-9 > top of Msdn Tech,.NET Development,64-Bit .NET Framework Development....
# 6

Here is some useful information from one of the 64 bit CLR team member's blogs:
http://blogs.msdn.com/joshwil/archive/2005/08/10/450202.aspx

Hope this helps,
Josh Lindenmuth

JoshLindenmuth at 2007-9-9 > top of Msdn Tech,.NET Development,64-Bit .NET Framework Development....
# 7
Thanks, that's exactly what I meant.
tommazzo at 2007-9-9 > top of Msdn Tech,.NET Development,64-Bit .NET Framework Development....
# 8
Please note that some information in this thread is not correct. In unmanaged Visual C++ sizeof(int) == sizeof(long) == 4 on both 32- and 64-bit machines.

Thanks,
Eugene

EugeneNalimov at 2007-9-9 > top of Msdn Tech,.NET Development,64-Bit .NET Framework Development....

.NET Development

Site Classified