x64 上的 sizeof(int)? [英] sizeof(int) on x64?
问题描述
当我在 C#.NET 项目中执行 sizeof(int)
时,我得到的返回值为 4.我将项目类型设置为 x64,那么为什么它说的是 4 而不是 8?这是因为我正在运行托管代码吗?
When I do sizeof(int)
in my C#.NET project I get a return value of 4. I set the project type to x64, so why does it say 4 instead of 8? Is this because I'm running managed code?
推荐答案
有 各种 64-位数据模型;Microsoft 将 LP64 用于 .NET:两者长em>s 和指针是 64 位的(尽管 C 风格的指针只能在 C# 中的 unsafe
上下文中使用,或者作为 IntPtr
值不能用于指针-算术).将此与 ILP64 进行对比,其中 int 也是 64 位.
There are various 64-bit data models; Microsoft uses LP64 for .NET: both longs and pointers are 64-bits (although C-style pointers can only be used in C# in unsafe
contexts or as a IntPtr
value which cannot be used for pointer-arithmetic). Contrast this with ILP64 where ints are also 64-bits.
因此,在所有平台上,int
是 32 位,long
是 64 位;您可以在基础类型 System.Int32
和 System.Int64
的名称中看到这一点.
Thus, on all platforms, int
is 32-bits and long
is 64-bits; you can see this in the names of the underlying types System.Int32
and System.Int64
.
这篇关于x64 上的 sizeof(int)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!