The "Clockwise/Spiral Rule"

The "Clockwise/Spiral Rule"
void (*signal(int, void (*fp)(int)))(int); 
Question:
What is 'signal' ?
 
#include  < cstdio >
using   namespace  std;

void  f( int );
void  ( * pf)( int ), ( * qf)( int );
void  ( * hf( int void ( * )( int )))( int );

typedef 
void  ( * sighandler_t)( int );

sighandler_t signal(
int , sighandler_t);


void  f( int  a) 
{
    printf(
"void f(int %d)\n", a);
}


void  ( * hf( int  _i,  void ( * _pf)( int )))( int )
{
    printf(
"_i = %d\n", _i);
    _pf(_i);
    
return _pf;
}


sighandler_t signal(
int  signum, sighandler_t sighandler)
{
    printf(
"signal num = %d\n", signum);
    sighandler(signum);
    
return sighandler;
}


int  main()
{
    pf 
= &f;
    qf 
= hf(12, pf);
    qf(
23);
    
    signal(
54, f);
    
return 0;
}



void (*signal(int, void (*)(int)))(int);
Answer:
signal is a function, passing { an int and a pointer [to a function passing an int returning nothing (void)]}, returning { a pointer [to a function passing an int returning nothing (void)]}.

你可能感兴趣的:(The "Clockwise/Spiral Rule")