How do vararg functions find out the number of arguments in machine code?

后端 未结 4 2096
清酒与你
清酒与你 2020-12-03 11:51

How can variadic functions like printf find out the number of arguments they got?

The amount of arguments obviously isn\'t passed as a (hidden) parameter (s

4条回答
  •  一整个雨季
    2020-12-03 11:59

    Implicitly, from the format string. Note that stdarg.h doesn't contain any macros to retrieve the total "variable" number of arguments passed. This is also one of the reasons the C calling convention requires the caller to clean the stack, even though this increases code size.

提交回复
热议问题