I would like to write a function that takes a pointer to multidimensional array. For example:
#include <stdio.h>
void print_matrix(int channel, int row, int column, int *matrix);
int main(void) {
int test[4][5][6];
int counter = 1;
for (int channel = 0; channel < 4; channel++) {
for (int row = 0; row < 5; row++) {
for (int column = 0; column < 6; column++) {
test[channel][row][column] = counter;
counter += 1;
}
}
}
print_matrix(4, 5, 6, test);
}
void print_matrix(int channel, int row, int column, int *matrix) {
for (int chn = 0; chn < channel; chn++) {
for (int r = 0; r < row; r++) {
for (int c = 0; c < column; c++) {
printf("%d ", *(matrix + (chn * row * column + r * column + c)));
}
printf("\n");
}
printf("\n\n");
}
}
But when I compile the code, the compiler gave following warning.
warning: incompatible pointer types passing 'int [4][5][6]' to parameter of type 'int *' [-Wincompatible-pointer-types]
Before I asked the question, I searched the warning and I found the different solution. like
void print_matrix(int channel, int row, int column, int matrix[channel][row][column]) ...
if I am not wrong, I know that C holds array as sequential. for example:
int holder[2][3][4]; // is equal to int holder[24] in ram
//holder[0][1][0] is equal to *(holder + 4)
My question is that the warning is important? and if I know what to do, can I ignore this warning?