You should only use “async-signal safe” functions in the handler to avoid deadlocks (async-signal safety is stronger than thread safety, because the main program is completely interrupted until the handler has terminated). For example, printf is not safe, but write is, so you should write text on the terminal using write(STDOUT_FILENO, text, text_length); (more details here).

Function pointers

Normal fn

int fonction(double x, bool b);// declaration of the functionint(*pf)(double,bool);// declaration of the pointer to function
pf =&fonction;// initialization of the pointer(*pf)(9,true);// call of the function through the pointer

Using typedef:

int fonction(double x, bool b);// declaration of the functiontypedefint(*fnIdb)(double,bool);// declaration of pointer type
fnIdb pf =&fonction;// declaration and initialization of the pointer(*pf)(9,true);// call of the function through the pointer

Static member fn

Static member functions behave the same way than normal functions.

class ClasseS {public:staticint fonction(double x, bool b);};// declaration of the functionint(*psf)(double,bool);// declaration of the pointer to the function
psf =&ClasseS::fonction;// initialization of the pointer(*psf)(5,true);// call of the static member function through the pointer

Non virtual member fn

Member functions have a hidden parameter (a pointer to this), so the pointer needs an object to call the function. If the member function is non virtual, the address of the member function is the same for all objects.

class Classe {public:int fonction(double x, bool b);};// declaration of the functionint(Classe::*pcf)(double,bool);// declaration of the pointer to function
pcf =&Classe::fonction;// initialization of the pointer
Classe classe;(classe.*pcf)(9,true)// call of the member function through the pointer

Virtual member fn

The syntax is the same as for non virtual member functions, and the pointer points to the place in the object where the address of the function is stored, so that it always points to the right function.