You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
There's an interesting issue with languages that have
usize
, in that you can never convert between anint
and ausize
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 typeT
with indices of typeu32
. That means the array has a maximum size limit, but also means we can read indices intou32
without risk of coercion failures.The text was updated successfully, but these errors were encountered: