posts - 43,  comments - 9,  trackbacks - 0
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(intvoid(*)(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)]}.

posted on 2011-08-31 13:07 wolf5x 阅读(196) 评论(0)  编辑 收藏 引用 所属分类: c/c++

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理


<2009年9月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

"Do not spend all your time on training or studying - this way you will probably become very exhausted and unwilling to compete more. Whatever you do - have fun. Once you find programming is no fun anymore – drop it. Play soccer, find a girlfriend, study something not related to programming, just live a life - programming contests are only programming contests, and nothing more. Don't let them become your life - for your life is much more interesting and colorful." -- Petr

留言簿(3)

随笔分类(59)

随笔档案(43)

cows

搜索

  •  

最新评论

评论排行榜