alurm
Joined 3 years ago
Karma
103
Submissions
32
Member since
Feb 11
Joined 3 years ago
`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:
void f(int *(*ints)[2]) {
for (size_t i = 0; i < (size_t)vec_len[*ints]; i++) printf("f: %d\n", vec_ptr[*ints][i]);
}
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.
Interestingly, I think my approach will work fine on CHERI, since the pointer is never dereferenced, but I didn't test this. But yeah, there are some architectures where it would fail.
Edit: mentioned this in the README explicitly. Thanks!
Edit: I have updated the documentation to mention this explicitly, thanks!