开发者

C Programming: Strange looking array declaration

开发者 https://www.devze.com 2023-03-27 01:33 出处:网络
I\'m looking at the source code in one of the FFMPEG files and found a construct that looks really strange to me. Can sb please explain what is happening here?

I'm looking at the source code in one of the FFMPEG files and found a construct that looks really strange to me. Can sb please explain what is happening here?

init and query_formats are actually functions that have been declared before in the file.

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}},
};

What are the "." doing in there. How would you access all these points. What would be saved in the compartments of the array (pointer addresses?!)?

I'm a bit confused..

Also, how do you learn about how the code of a third party programmer works, if there are almost no comments around? Documentation doesn't exist either..

PS: This is what the init function looks like:

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


This is C99.

It allows to initialize structures by name.

For example the structure:

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

Can be initialized as:

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

This requires up-to-date compiler that supports the latest standards: C99.


It's called a designated initializer, and is part of the C99 standard. Have a look here to learn more.

0

精彩评论

暂无评论...
验证码 换一张
取 消