Search code examples
cfunction-pointersdeclarationtypedeffunction-declaration

How to define function type with typedef?


I would like to know if it is possible to define a function type using typedef, I tried this syntax:

typedef int (*) (void *, void *) order;

But it doesn't work. Error message : expected identifier or '(' before ')' token


Solution

  • The alias name should be placed where a variable name would be if it was a variable declaration.

    Here:

    typedef int (*order) (void *, void *);
    //            ^~~~~
    

    Or, if you want a function type rather than a pointer-to-function:

    typedef int order(void *, void *);