Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any programming language where the variables types sizes in bits depends on the platform (32 vs 64 bit)?

I am C# developer and I am almost certain that in this language an "int" is always 32 bits regardless of the platform (32 vs 64 bit), a "long" is always 64 bits, a float is 32 and a double 64 and so on.

There is any language where its not like that? Where the int size depends on the processor?

like image 487
Jader Dias Avatar asked Dec 02 '22 08:12

Jader Dias


2 Answers

The sizes of int etc in C/C++ aren't formally defined - they are compiler specific; see here for more details.

The C# designers thankfully formally dictated in the spec: int = System.Int32, long = System.Int64, etc - so you don't have to worry about it changing. The only easily noticeable difference on x64 is IntPtr.Size.

like image 69
Marc Gravell Avatar answered May 07 '23 09:05

Marc Gravell


In C++, for instance, int is defined to be the "natural" word size of the processor. If you look in limits.h (or climits, both of which are part of Standard Library), you'll see INT_MIN and INT_MAX constants, which define a valid range of the int type. It's required for INT_MIN to be -32767 or less, and for INT_MAX to be at least 32767.

like image 35
Anton Gogolev Avatar answered May 07 '23 11:05

Anton Gogolev