I need a pointer to a static 2-dimensional array. How is this done?
static uint8_t l_matrix[10][20];
void test(){
uint8_t **matrix_ptr = l_matrix; //wron
In C99 (supported by clang and gcc) there's an obscure syntax for passing multi-dimensional arrays to functions by reference:
int l_matrix[10][20];
void test(int matrix_ptr[static 10][20]) {
}
int main(void) {
test(l_matrix);
}
Unlike a plain pointer, this hints about array size, theoretically allowing compiler to warn about passing too-small array and spot obvious out of bounds access.
Sadly, it doesn't fix sizeof()
and compilers don't seem to use that information yet, so it remains a curiosity.