Zelid
Zelid

Reputation: 7195

What does "void (* parse_arg_function)(const char*)" function argument mean in C?

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.

Upvotes: 1

Views: 512

Answers (5)

Mark Rushakoff
Mark Rushakoff

Reputation: 258348

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.

Upvotes: 3

Abel
Abel

Reputation: 57169

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.

Upvotes: 1

James McNellis
James McNellis

Reputation: 355177

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

Upvotes: 1

Alexander Gessler
Alexander Gessler

Reputation: 46637

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

Upvotes: 1

SLaks
SLaks

Reputation: 887767

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

For more information, see here.

Upvotes: 6

Related Questions