开发者

making sense of this parameter being passed

Linux gcc 4.4.1

I have this function that passes this second parameter that casts it to a different type. I am just wondering am I correct?

It looks to me that it is casting the function evt_hdlr to a void * type to a long pointer type.

if(enable_evt_hdlr(EV_ANY, (long (*) (void *)) evt_hdlr开发者_开发问答) == -1)
{
..
}

The function evt_hdlr definition looks like this:

static int32_t evt_hdlr(void);

Many thanks for any suggestions,


You cast a function without parameters and returning an int32_t to a function-pointer with a void* parameter, returning a long. This might work, but it's more luck than skill (long and int32_t are not necessarily the same).

If you can't change the type of enable_evt_hdlr or evt_hdlr, then make an in-between function:

static long my_evt_hdlr(void*)
{
  return (long) evt_hdlr();
}

and pass this to event-handler. This way the stack will be handled as promised.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜