LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1504|回复: 4

int (*new_phase_hook) __P((int)) = NULL; ?

[复制链接]
发表于 2009-6-9 17:08:34 | 显示全部楼层 |阅读模式
这句C语言的定义是什么意思?
下面是用到它的一个函数:
void
new_phase(p)
    int p;
{
    phase = p;
    if (new_phase_hook)
        (*new_phase_hook)(p);
    notify(phasechange, p);
}
主要是解释一下这个if语句就可以了。
发表于 2009-6-9 20:32:14 | 显示全部楼层
if语句就是判断函数指针new_phase_hook是否为空呀
回复 支持 反对

使用道具 举报

发表于 2009-6-9 21:37:45 | 显示全部楼层
new_phase_hook是一个指向函数的指针
回复 支持 反对

使用道具 举报

 楼主| 发表于 2009-6-10 08:33:51 | 显示全部楼层
Post by neubuffalo;1995969
new_phase_hook是一个指向函数的指针

由于无法输入下划线,用-代表下划线:
new-phase-hook确实像函数指针,我把他的定义处找到:
int (*new-phase-hook) --P((int)) = NULL;
好像跟别的函数指针的定义不一样,其中--P的定义为:
#ifndef --P
#ifdef --STDC--
#define --P(x)  x
#else
#define --P(x)  ()
#endif
#endif
能给详细解释一下这个指针是如何定义的马?
--P((int))如何解释?
回复 支持 反对

使用道具 举报

发表于 2009-6-10 10:05:39 | 显示全部楼层
#ifndef --P
#ifdef --STDC--
#define --P(x) x 此时int (*new-phase-hook) --P((int)) = NULL展开就是int (*new-phase-hook)(int)=NULL。
#else
#define --P(x) ()此时int (*new-phase-hook) --P((int)) = NULL展开就是int (*new-phase-hook)()=NULL。
#endif
#endif
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表