Felix Kater wrote:
Hi,
I've got a function with an array of 12 function pointers as an argument. When calling it: Is there a way to directly insert and fill the array argument (using braces {} or whatever) -- or do I need to fill an array first and then pass it as an argument?
The following is not ISO-C (gcc generates the warning:
"a.c:20: warning: ISO C90 forbids compound literals"),
but it might be what you're looking for:
int foo0(void) {return 0;}
int foo1(void) {return 1;}
int foo2(void) {return 2;}
int foo3(void) {return 3;}
void FOO( int (**f)(void), int i)
{
for (; i>=0; i--)
printf("%d\n", f[i]());
}
typedef int (*f_array[4])(void);
int main(void)
{
f_array f;
FOO( (f_array){foo0, foo1, foo2, foo3}, 3);
}