3 ms·
Fair enough then, I suppose that in C you have to do something like that if you want both that your matrix size is decidable at runtime, and to be able to index
by sbmassey 9y ago
Fair enough then, I suppose that in C you have to do something like that if you want both that your matrix size is decidable at runtime, and to be able to index it with m[x][y] rather than some function.
- iamrecursion 9y agoThat’s not strictly true. You can malloc an m*n sized array and then assign to another array the pointer to the head of each column, allowing you standard style indexing.
- PeterisP 9y agoIf you do that, every access will actually dereference that pointer and won't be able to optimize the standard style indexing to a multiplication and addition, so this still carries a significant performance cost.
- Peaker 9y agoYou can always use a macro (or inline function, if the array is a rich wrapper type): arr(m, x, y) Not quite as nice, but not too bad.