|
|
|
|
|
by alurm
3 days ago
|
|
Yeah, I've added macros `vec_len` and `vec_ptr` (or, enums, actually), which help somewhat. `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. |
|