tags:

views:

80

answers:

5

What does the last function argument mean in C language? Please, point to documentation where I can read about it.

void parse_options( int argc, char **argv, const OptionDef *options, 
                   void (* parse_arg_function)(const char*) )

Thanks.

+6  A: 

This is a pointer to a function that takes a const char* and returns void.

For more information, see here.

SLaks
+3  A: 

It's a function pointer. The function is called parse_arg_function, it accepts a const char* argument, and it returns void.

In the case you've shown, the function pointer is essentially being used as a callback. Inside that function, it might be used along the lines of

// ...
for (int i = 0; i < argc; i++)
{
    parse_arg_function(argv[i]);
}
// ...

You might want to read over this function pointer tutorial for a more in-depth discussion.

Mark Rushakoff
+1  A: 

This is a good introduction on function pointers. Think of them as the address of the code pertaining to a function in memory.

Alexander Gessler
+1  A: 

When in doubt about what a declaration means in C, you can ask cdecl:

declare parse_arg_function as pointer to function (pointer to const char) returning void

James McNellis
Thanks, interesting link.
+1  A: 

This is a function from the ffmpeg library. Quote from the online documentation about ffmpeg:

parse_arg_function   Name of the function called to process every argument without a leading option name flag. NULL if such arguments do not have to be processed.

In other words: when you want to do some processing yourself for each argument, you can give your own function. Otherwise, just use NULL.

Abel