开发者

Pointer to function as parameter, using typedef

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜