免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 2718 | 回复: 12
打印 上一主题 下一主题

请教,下面奇怪的定义方式是怎么回事? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-07-21 17:34 |只看该作者 |倒序浏览
这两天在阅读ffmpeg的代码( 真是痛苦的工作...... ),其中有一段代码,是这样写的:

const OptionDef options[] = {
    /* main options */
    { "focus", HAS_ARG | OPT_VIDEO, {(void*)fcous}, "do focus", "focus" },
    { "osd", OPT_VIDEO, {(void*)Input_OSD}, "add input OSD function", "OSD" },
    { "motion", HAS_ARG | OPT_VIDEO, {(void*)read_motion_config}, "read motion configuration", "motion" },
    { "L", 0, {(void*)show_license}, "show license" },
    { "h", 0, {(void*)show_help}, "show help" },
  
   。。。。。。。(中间的内容太多,省略掉)

    { NULL, },
};
     

其中的两个函数定义:

void Input_OSD(const char *arg)
{
    do_OSD();
}


static void show_license(void)
{
    show_banner();
    printf(
    "This library is free software; you can redistribute it and/or\n"
    "modify it under the terms of the GNU Lesser General Public\n"
    "License as published by the Free Software Foundation; either\n"
    "version 2 of the License, or (at your option) any later version.\n"
    "\n"
    "This library is distributed in the hope that it will be useful,\n"
    "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
    "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n"
    "Lesser General Public License for more details.\n"
    "\n"
    "You should have received a copy of the GNU Lesser General Public\n"
    "License along with this library; if not, write to the Free Software\n"
    "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n"
    );
    exit(1);
}

虽然能大概猜出这段程序是干什么的,不过细节的方面却一点儿都不明白,那个朋友能解释一下,而且Input_OSD函数是需要输入的,想上面那样什么都不写,到底是怎么通过的?

论坛徽章:
0
2 [报告]
发表于 2007-07-21 18:00 |只看该作者
(void*)Input_OSD 把函数指针转成void*保存起来

论坛徽章:
95
程序设计版块每日发帖之星
日期:2015-09-05 06:20:00程序设计版块每日发帖之星
日期:2015-09-17 06:20:00程序设计版块每日发帖之星
日期:2015-09-18 06:20:002015亚冠之阿尔艾因
日期:2015-09-18 10:35:08月度论坛发贴之星
日期:2015-09-30 22:25:002015亚冠之阿尔沙巴布
日期:2015-10-03 08:57:39程序设计版块每日发帖之星
日期:2015-10-05 06:20:00每日论坛发贴之星
日期:2015-10-05 06:20:002015年亚冠纪念徽章
日期:2015-10-06 10:06:482015亚冠之塔什干棉农
日期:2015-10-19 19:43:35程序设计版块每日发帖之星
日期:2015-10-21 06:20:00每日论坛发贴之星
日期:2015-09-14 06:20:00
3 [报告]
发表于 2007-07-21 19:08 |只看该作者
原帖由 封神 于 2007-7-21 17:34 发表
这两天在阅读ffmpeg的代码( 真是痛苦的工作...... ),其中有一段代码,是这样写的:

const OptionDef options[] = {
    /* main options */
    { "focus", HAS_ARG | OPT_VIDEO, {(void*)fcous}, "d ...

你的疑问是什么?

论坛徽章:
0
4 [报告]
发表于 2007-07-21 19:40 |只看该作者
什么意思啊 看不明白!

论坛徽章:
0
5 [报告]
发表于 2007-07-21 20:24 |只看该作者
大哥,你不会是没学过"函数指针"吧?

论坛徽章:
0
6 [报告]
发表于 2007-07-22 02:16 |只看该作者

论坛徽章:
0
7 [报告]
发表于 2007-07-22 14:13 |只看该作者
不是函数指针的问题,我想知道的是" { "focus", HAS_ARG | OPT_VIDEO, {(void*)fcous}, "do focus", "focus" },"这一整行是什么意思.

论坛徽章:
95
程序设计版块每日发帖之星
日期:2015-09-05 06:20:00程序设计版块每日发帖之星
日期:2015-09-17 06:20:00程序设计版块每日发帖之星
日期:2015-09-18 06:20:002015亚冠之阿尔艾因
日期:2015-09-18 10:35:08月度论坛发贴之星
日期:2015-09-30 22:25:002015亚冠之阿尔沙巴布
日期:2015-10-03 08:57:39程序设计版块每日发帖之星
日期:2015-10-05 06:20:00每日论坛发贴之星
日期:2015-10-05 06:20:002015年亚冠纪念徽章
日期:2015-10-06 10:06:482015亚冠之塔什干棉农
日期:2015-10-19 19:43:35程序设计版块每日发帖之星
日期:2015-10-21 06:20:00每日论坛发贴之星
日期:2015-09-14 06:20:00
8 [报告]
发表于 2007-07-22 14:55 |只看该作者
原帖由 封神 于 2007-7-22 14:13 发表
不是函数指针的问题,我想知道的是" { "focus", HAS_ARG | OPT_VIDEO, {(void*)fcous}, "do focus", "focus" },"这一整行是什么意思.

初始化结构体嘛。

论坛徽章:
0
9 [报告]
发表于 2007-07-22 15:15 |只看该作者
读读OptionDef 的定义就知道了

论坛徽章:
0
10 [报告]
发表于 2007-07-22 16:28 |只看该作者

回复 #1 封神 的帖子

OptionDef是个结构体啊。
options是个结构体数组啊。
结构体和数组的初始化都用“{}”括起来,“,”分开啊。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP