How to count the number of arguments passed to a function that accepts a variable number of arguments?

前端 未结 10 2142
旧时难觅i
旧时难觅i 2020-12-01 05:18

How to count the no of arguments passed to the function in following program:

#include
#include
void varfun(int i, ...);
int m         


        
10条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-01 05:29

    Appending or NULL at the end makes it possible for me to have any number of arguments and not worry about it going out of the stack

    #include 
    template
    inline void variadic_fun1(_Ty param1,...)
    {
        va_list arg1;
        //TO_DO
    
        va_end(arg1);
    }
    template 
    void variadic_fun2(_Ty param1,...)
    {
        va_list arg1;
        va_start(arg1, param1);
        variadic_fun1(param1, arg1, 0);
        va_end(arg1);
    }
    

提交回复
热议问题