[Feature Request] Introduce size_t type to language
Closed this issue · 4 comments
Since 4 languages use it for array length it'd be beneficial to have it.
What it'd transpile to:
- C, C++, D, OpenCL C -
size_t
(typedef/alias to int/long depending on 32/64bit platform) - C#, Java, Swift -
int
(seems to not have any distinction) - JavaScript, Python - nothing (dynamic types, no way to emit type of variable)
- TypeScript -
number
(no other distinct numeric types)
Partially related to #97
In .NET there's Array.LongLength
and arrays can be subscripted by long
s. Unlike List
s.
In JavaScript and Python arrays of numeric types are typed. So the size type needs to be defined somehow.
C# has nint
and nuint
.
I added an initial implementation. Needs testing and documentation. The type is named nint
.
I opted for a signed type, hence it's ptrdiff_t
in C, C++, D and OpenCL. This way loops like
for (nint i = foo.Length; --i >= 0; )
are not endless loops. I know no machine where 64-bit vs 63-bit size would make a difference.
Browsers cannot create typed arrays above 32-bit counts. But Python happily creates large bytearray
s and array
s. Therefore nint
is 32-bit in JavaScript and 64-bit in Python.