What happens internally when a functions that uses varargs is called? Are the arguments themselves stored on the heap or on the stack like any other arguments. If on the stack, how does that work?
What happens internally when a functions that uses varargs is called? Are the arguments
Share
In C, function arguments are both pushed onto and pulled from the stack by the caller function. The caller function knows how many items were pushed and so it is also able to pull them back after the call. The callee can only infer the number of the arguments from other parameters, like the format string of
printf().In Pascal, for example, the arguments on the stack are pulled by the callee. As the callee is not aware of the number of items pushed, it cannot restore the stack to its previous state either. That’s why it’s impossible to implement varargs in Pascal.