How can I typedef a function pointer that takes a function of its own type as an argument?

前端 未结 2 1214
误落风尘
误落风尘 2020-12-19 01:17

Example: A function that takes a function (that takes a function (that ...) and an int) and an int.

typedef void(*Func)(void (*)(void (*)(...), int), int);
<         


        
2条回答
  •  北荒
    北荒 (楼主)
    2020-12-19 02:17

    You can wrap the function pointer in a struct:

    struct fnptr_struct;
    typedef void (*fnptr)(struct fnptr_struct *);
    struct fnptr_struct {
      fnptr fp;
    };
    

    I'm not sure if this is an improvement on casting. I suspect that it's impossible without the struct because C requires types to be defined before they are used and there's no opaque syntax for typedef.

提交回复
热议问题