4
int myFunc(int a, int b, int c, int d[][c]) {
    //code
}

I've tried this:

int myFunc(int, int, int, int *);

And this:

int myFunc(int, int, int, int *[int]);

And this:

int myFunc(int, int, int, int **);

But none of them seem to work. I think I'm having trouble pinning down the last parameter's type. Any help would be greatly appreciated.

user3735278
  • 261
  • 3
  • 13

2 Answers2

5

Now try this

int myFunc(int a, int b, int c, int (*)[c]);
user3735278
  • 261
  • 3
  • 13
haccks
  • 104,019
  • 25
  • 176
  • 264
3

If you want to skip all parameters' names for your signature, then since C99 Standard you can use this:

int myFunc(int, int, int, int [][*]);

or even combining with haccks's answer:

int myFunc(int, int, int, int (*)[*]);

Note that these both forms are equivalent, it's more like matter of preference, which one to take.

The [*] means that array size is obtained from one of its previous parameters and you don't have to tell exactly which one needs to be taken. There might be even more than one, thus following declaration:

int someFunc(int m, int n, int [][m+n]);

is legal in C.

Here is the basic program, so you can see it that works for you:

#include <stdio.h>

int myFunc(int, int, int, int [][*]);

int myFunc(int a, int b, int c, int d[][c]) {
    return d[0][0];
}

int main(void)
{       
    printf("%d\n", myFunc(1, 1, 2, (int[1][2]){{3, 5}}));

    return 0;
}
Community
  • 1
  • 1
Grzegorz Szpetkowski
  • 36,988
  • 6
  • 90
  • 137