3 karma · joined Aug 22, 2019 (7y ago) · 2 submissions
comment 7y ago · link · parent
int b[const 42][24][*]
but you can get more fun with variably modified array parameters instead of just constants like 42. For example, double sum_a_weird_shaped_matrix(int n, double array[n][3*n]) {
double total = 0;
for (int x = 0; x < n; ++x) {
for (int y = 0; y < 3 * n; ++y) {
total += array[x][y];
}
}
return total;
}
has a variable and a more complicated expression in those positions.But those variably modified parameters can have arbitrary expressions in them, like
int last(size_t len, int array[restrict static (printf("getting the last element of an array of %zu ints\n", len), len--)]) {
return array[len];
}
C++ denies us this particular joy which could have made function overload resolution even more fun.