Function types

Contents

Function types#

Function types describe a signature; function-pointer values carry the address.

A function-pointer variable.

int  (*handler)(int, int);   /* pointer to int(int,int) */
handler = &add;
handler(1, 2);

A typedef makes the signature reusable.

typedef int (*comparator_t)(const void *, const void *);
qsort(xs, n, sizeof xs[0], (comparator_t)compare_ints);

References#

  • Functions for function definition and the calling convention.

  • Pointers for the underlying pointer rules.