How to use va_start()?

陌路散爱 提交于 2021-01-27 14:20:58

问题


In a function with variable arguments, we initialize an object of type va_list ,'ap' with the function va_start() as:

void va_start(va_list ap, parmN);

I don't understand

1.what type of objects can be passed as parMN(last known parameter). I've done with examples of passing integers, strings with format specifiers, structures etc.

2. How the parMN describes the following optional parameters.


回答1:


The C standard says that va_start() is actually a macro, not a function, so it can do things a function couldn't. The details are highly implementation dependent but you could imagine that it takes the address of parmN to determine the stack address of the next parameter. There's no need for va_start() to know about the types of the following parameters because that information is passed to va_arg(), which is another macro.



来源:https://stackoverflow.com/questions/57036703/how-to-use-va-start

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!