Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is an int a 64-bit integer in 64-bit C#?

In my C# source code I may have declared integers as:

int i = 5; 

or

Int32 i = 5; 

In the currently prevalent 32-bit world they are equivalent. However, as we move into a 64-bit world, am I correct in saying that the following will become the same?

int i = 5; Int64 i = 5; 
like image 474
Guy Avatar asked Oct 02 '08 21:10

Guy


People also ask

What is 64-bit integer in C?

The long long data type makes handling 64 bit integers easy. In C language, an unsigned number over 32 bits cannot exceed the value of 4,294,967,295. You may find you are required to handle larger numbers and for this you need these numbers to be coded in 64-bit.

What is int 64bit?

Int64 is an immutable value type that represents signed integers with values that range from negative 9,223,372,036,854,775,808 (which is represented by the Int64. MinValue constant) through positive 9,223,372,036,854,775,807 (which is represented by the Int64. MaxValue constant.

Does C support 64-bit?

Microsoft C/C++ features support for sized integer types. You can declare 8-, 16-, 32-, or 64-bit integer variables by using the __intN type specifier, where N is 8, 16, 32, or 64.


2 Answers

No. The C# specification rigidly defines that int is an alias for System.Int32 with exactly 32 bits. Changing this would be a major breaking change.

like image 126
Jon Skeet Avatar answered Sep 21 '22 15:09

Jon Skeet


The int keyword in C# is defined as an alias for the System.Int32 type and this is (judging by the name) meant to be a 32-bit integer. To the specification:

CLI specification section 8.2.2 (Built-in value and reference types) has a table with the following:

  • System.Int32 - Signed 32-bit integer

C# specification section 8.2.1 (Predefined types) has a similar table:

  • int - 32-bit signed integral type

This guarantees that both System.Int32 in CLR and int in C# will always be 32-bit.

like image 43
Tomas Petricek Avatar answered Sep 19 '22 15:09

Tomas Petricek