If you cannot know the size at compile time, you will have to pass it to the function and then use pointer arithmetic. Or use an array of pointers to 1-D arrays, which you will have to allocate.
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
void func_static(uint64_t size_1, uint64_t size_2, uint64_t *array)
{
uint64_t x, y;
for(x = 0; x < size_1; x++) {
for(y = 0; y < size_2; y++) {
printf("%d\n", array[x * size_2 + y]);
}
}
}
void func_dynamic(uint64_t size_1, uint64_t size_2, uint64_t **array)
{
uint64_t x, y;
for(x = 0; x < size_1; x++) {
for(y = 0; y < size_2; y++) {
printf("%d\n", array[x][y]);
}
}
}
int main()
{
uint64_t array_static[2][4] = { { 1, 2, 3, 4 }, {5, 6, 7, 8} };
uint64_t **array_dynamic;
uint64_t size_1 = 2;
uint64_t size_2 = 4;
uint64_t x, y;
func_static(sizeof(array_static)/sizeof(array_static[0]), sizeof(array_static[0])/sizeof(array_static[0][0]), (uint64_t *)&array_static);
array_dynamic = malloc(size_1 * sizeof(uint64_t));
for(x = 0; x < size_1; x++) {
array_dynamic[x] = malloc(size_2 * sizeof(uint64_t));
}
for(x = 0; x < size_1; x++) {
for(y = 0; y < size_2; y++) {
array_dynamic[x][y] = array_static[x][y];
}
}
func_dynamic(size_1, size_2, array_dynamic);
return 0;
}