What is the procedure of the function call, what is the stack out of the stack,
When another function is called during the run of a function, the system needs to complete three things before running the called function.
- All the actual parameters, the return address and other information are passed to the tuned function to save,
- Allocating storage space for local variables (also including formal parameters) of the modulated function
- Transfer control to the entry of the transferred function,
There are three things that the system has to do before returning from the tuned function to the keynote function.
- Save the returned result of the tuned function,
- Releases the storage space occupied by the tuned function,
- Transfers control to the calling function according to the return address saved by the tuned function.
When more than one function calls each other, according to the principle of returning first, the information transfer and control transfer between the above functions must be implemented by the stack, that is, the system arranges the data space required by the whole program to run in a stack, whenever a function is called, a storage area is allocated at the top of the stack, and a stack operation is performed. Whenever a function exits, the store is freed, and a stack operation is performed, and the currently running function is always at the top of the stack.
What is the procedure of a function call?