C编程:奇怪的数组声明

时间:2011-08-11 09:15:36

标签: c arrays pointers

我正在查看其中一个FFMPEG文件中的源代码,发现一个看起来很奇怪的构造。请问某人能解释一下这里发生了什么吗?

init和query_formats实际上是之前在文件中声明的函数。

AVFilter avfilter_vf_fade = {
    .name          = "fade",
    .description   = NULL_IF_CONFIG_SMALL("Fade in/out input video"),
    .init          = init,
    .priv_size     = sizeof(FadeContext),
    .query_formats = query_formats,

    .inputs    = (AVFilterPad[]) {{ .name            = "default",
                                    .type            = AVMEDIA_TYPE_VIDEO,
                                    .config_props    = config_props,
                                    .get_video_buffer = avfilter_null_get_video_buffer,
                                    .start_frame      = avfilter_null_start_frame,
                                    .draw_slice      = draw_slice,
                                    .end_frame       = end_frame,
                                    .min_perms       = AV_PERM_READ | AV_PERM_WRITE,
                                    .rej_perms       = AV_PERM_PRESERVE, },
                                  { .name = NULL}},
    .outputs   = (AVFilterPad[]) {{ .name            = "default",
                                    .type            = AVMEDIA_TYPE_VIDEO, },
                                  { .name = NULL}},
};

什么是“。”在那里做。您将如何访问所有这些点。什么会保存在数组的隔间(指针地址?!)?

我有点困惑..

另外,如果几乎没有评论,你如何了解第三方程序员的代码是如何工作的?文档也不存在..

PS:这是init函数的样子:

static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
{
...
}

2 个答案:

答案 0 :(得分:6)

这是C99。

它允许按名称初始化结构。

例如结构:

struct foo {
   int x,y;
   char *name;
};

可以初始化为:

struct foo f = { 
 .name = "Point",
 .x=10,
 .y=20
};

这需要支持最新版本的最新编译器 标准:C99。

答案 1 :(得分:1)

它被称为指定的初始化程序,是C99标准的一部分。查看here了解详情。

相关问题