2

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)
{
...
}
asked Aug 11, 2011 at 9:15
1
  • They are called "designated initializers". Commented Aug 11, 2011 at 9:18

2 Answers 2

6

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.

answered Aug 11, 2011 at 9:17
Sign up to request clarification or add additional context in comments.

1 Comment

Ok, I see. What does it mean if you use a function like has been done in the example .init = init where init is a function that was declared earlier? Does init now hold the result of the function or is it being assigned the address?
1

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

answered Aug 11, 2011 at 9:19

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.