Calling a variadic function with an unknown number of parameters

前端 未结 5 1498
长情又很酷
长情又很酷 2021-01-14 15:14

Say I have a function that takes a variable number of parameters: I want to call this function from somewhere else, building the list of parameters, but without knowing in a

5条回答
  •  灰色年华
    2021-01-14 15:40

    You will need a terminating parameter, it may be NULL, or something else, that should never appear in your real arguments. Inside your function you can loop over the arguments until you reach a terminating NULL or any other value you choose to signal the end.

提交回复
热议问题