Royi Namir
Royi Namir

Reputation: 148524

int behavior at 32/64 bit process?

I'm a process of 64 bit, my int size is 8 bytes.

I'm referencing a dll which is compiled to 32 bit.

This dll has a function which accepts an int parameter.

What will happen?

I'm sending a 8 byte to a 4 byte "container" ?

Upvotes: 6

Views: 4326

Answers (4)

bytecode77
bytecode77

Reputation: 14820

int is always 32 bit (4 bytes) in C#, but not in some other languages like C++. System.IntPtr is 4 bytes on an x86 machine and 8 bytes on a 64 bit OS. Use this if you want OS dependend integer types.

Upvotes: 1

Ral Zarek
Ral Zarek

Reputation: 1076

In c# ints are the same size in 32bit and 64bit assemblies. int or Int32 is always 32bit while long or Int64 is always 64bit.

Upvotes: 4

V4Vendetta
V4Vendetta

Reputation: 38210

It always maps to System.Int32 hence would be needing only 4

Upvotes: 3

Marc Gravell
Marc Gravell

Reputation: 1062770

No, in 64-bit / C#, an int is still 4 bytes.

In C#, int is always merely an alias to global::System.Int32

What will change is the reference size and pointer size, but that is all abstracted by the IL anyway - nothing needs to change. Note, though, that the CLI is only going to be 32 bit xor (nand?) 64 bit. You might need one of them to be "Any CPU".

Upvotes: 18

Related Questions