While the following code behaves as expected on Godbolt, I'm wondering if, from a standard perspective, casting int [n][m] -> int [n*m]
was allowed.
#define ROW 2
#define COL 10
void test(int arr[ROW * COL]) {
for (int i = 0; i < (ROW * COL); i++) {
printf("%d\n", arr[i]);
}
}
int main() {
// build an array
int arr[ROW][COL];
for (int i = 0; i < ROW; i++) {
for (int j = 0; j < COL; j++) {
arr[i][j] = i * 10 + j;
}
}
// Make the conversion
int* converted = (int*)arr; //< The conversion
test(converted);
return 0;
}
If you want to try it: godbolt