Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sizeof(int) on x64?

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?

like image 719
iheartcsharp Avatar asked Mar 16 '09 20:03

iheartcsharp


People also ask

What is the return value of sizeof () in 64-bit machine?

So, the sizeof(int) simply implies the value of size of an integer. Whether it is a 32-bit Machine or 64-bit machine, sizeof(int) will always return a value 4 as the size of an integer.

Is int always 4 bytes?

On 16-bit systems (like in arduino), int takes up 2 bytes while on 32-bit systems, int takes 4 bytes since 32-bit=4bytes but even on 64-bit systems, int occupies 4 bytes.

Is long int 32 or 64-bit?

Windows: long and int remain 32-bit in length, and special new data types are defined for 64-bit integers.


2 Answers

The keyword int aliases System.Int32 which still requires 4 bytes, even on a 64-bit machine.

like image 60
Andrew Hare Avatar answered Sep 21 '22 21:09

Andrew Hare


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.

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.

like image 40
Ðаn Avatar answered Sep 19 '22 21:09

Ðаn