How do System.float
, System.int
and other primitives types work? I never understood how it was possible to make primitives structs and I wonder if I could make my own numeric type.
A primitive type is predefined by the language and is named by a reserved keyword. Primitive values do not share state with other primitive values. The eight primitive data types supported by the Java programming language are: byte: The byte data type is an 8-bit signed two's complement integer.
Primitive is the most fundamental data type usable in the Programming language. There are eight primitive data types: Boolean, byte, character, short, int, long, float, and double. In a Programming language, these data types serve as the foundation for data manipulation.
Primitive Data Types: These data types are built-in or predefined data types and can be used directly by the user to declare variables. example: int, char, float, bool, etc. Primitive data types available in C++ are: Integer.
Stack memory stores primitive types and the addresses of objects. The object values are stored in heap memory.
Assuming we're talking about a C# compiler which targets the Common Language Infrastructure (CLI), as almost everything does, it basically uses the primitive types exposed by the CLI.
There are effectively three levels of support to consider:
System.Decimal
. This is also part of the Common Type System (CTS) which means that if you create a const decimal
in C#, you can still consume it in VB, for example. But there's still no direct IL support.BigInteger
- you can write your own ones of these.The middle ground of the second bullet allows C# to have decimal literals and decimal constants, neither of which are possible for the third bullet. For example, BigInteger
doesn't have language support, so you can't write:
// This isn't valid
BigInteger bigInteger = 123456789012345678901234567890;
You'd have to parse a string representation instead. Likewise you can't have a const BigInteger
.
(In theory it would be possible to have a type with support in C# but not in the CTS. I don't know of any such types.)
Primitive types like int
and float
are supported directly by the processor, and the .net platform and languages have similar built-in support for them. So there are no way you could create your own primitives at the language level.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With