Passing variable number of arguments around

前端 未结 11 632
我寻月下人不归
我寻月下人不归 2020-11-22 07:16

Say I have a C function which takes a variable number of arguments: How can I call another function which expects a variable number of arguments from inside of it, passing a

11条回答
  •  既然无缘
    2020-11-22 07:45

    Let's say you have a typical variadic function you've written. Because at least one argument is required before the variadic one ..., you have to always write an extra argument in usage.

    Or do you?

    If you wrap your variadic function in a macro, you need no preceding arg. Consider this example:

    #define LOGI(...)
        ((void)__android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
    

    This is obviously far more convenient, since you needn't specify the initial argument every time.

提交回复
热议问题