开发者

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

Wh开发者_高级运维at 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.


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

For more information, see here.


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.


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


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


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜