|
|
|
|
|
by lefra
6 days ago
|
|
Enjoy the annoying-to-debug errors when someone inevitably mixes arr[0] with arr[1] and tramples the heap (this could be mitigated by accessing the fields with macros), or writes arr[3] because they forgot this is not a regular array. |
|
`arr[3]` should be flagged by the compiler it is known to the compiler that you're operating on an array.
You can pass `arr` as `&arr` to functions, then compiler will know the length of the array since the type would be `T ()[2]`.
And you can then use it like this:
Curiously, this is a rare case where the "inverted" `a[b]` requires less typing compared to `(b)[a]`.A compiler will not be able to flag `vec_len[ints]` though, which is unfortunate.