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

前端 未结 10 2130
旧时难觅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:55

    You can't. You have to manage for the caller to indicate the number of arguments somehow. You can:

    • Pass the number of arguments as the first variable
    • Require the last variable argument to be null, zero or whatever
    • Have the first argument describe what is expected (eg. the printf format string dictates what arguments should follow)

提交回复
热议问题