Whiley / RFCs

Request for Comment (RFC) proposals for substantial changes to the Whiley language.
3 stars 2 forks source link

Eliminating usize #99

Open DavePearce opened 2 years ago

DavePearce commented 2 years ago

There's an interesting issue with languages that have usize, in that you can never convert between an int and a usize without risking an overflow. How can we avoid this?

An interesting observation is that Java does not have this problem. In fact, Java limited array indices to int types (i.e. 32bit) which does indeed limit the maximum size of an array.

One option is to allow the user to specify this. For example, T[u32] indicates an array of type T with indices of type u32. That means the array has a maximum size limit, but also means we can read indices into u32 without risk of coercion failures.