问题描述:

I'm trying to create code which uses pointers to functions as parameteres, and I have to use a typedef.

I'm not a C pro. It feels like I'm getting there, but I can't seem to find a good explanation of the syntax of pointers to function.

I have a function fillArray:

long fillArray(long *array, int x, int y) {

//

}

then I want to make a typedef of a pointer to this function:

typedef long (*fArray)(long, int, int);

fArray pFill = fillArray;

and I want to give this pFill to a function called doThis():

int doThis (fArray pFill) {

return 0;

}

and calling it using:

int y = doThis(pFill);

What am I doing wrong?

网友答案:

Your typedef needs to be:

typedef long (*fArray)(long *, int, int);
                            ^
网友答案:

Your fillArray function accepts a long * as first parameter, you forgot a * into the typedef:

typedef long (*fArray)(long *, int, int);
相关阅读:
Top