The order of pushing onto the stack is determined at compile time.
The main thing that needs to be pushed onto the stack before a function call is the function parameters, and the parameters are all fixed (the variable parameters are just offsets determined by macros). The code for calling functions is placed in the code segment, and pushing onto the stack is done in the form of instructions, so the order is determined at compile time.
@lianera is right, the order of pushing onto the stack is determined at compile time.
Let me show you an example: I have a piece of code like this
#include <stdio.h>
int test_fun(int a, int b)
{
return a + b;
}
int main(int argc, char *argv[])
{
int A, B, ret;
A = 3;
B = 4;
ret = test_fun(A, B);
return 1;
}
After compilation, his assembly code looks like this
It doesn’t matter if you don’t understand assembly. During the compilation process, the order in which parameters are passed, and where on the stack (relative position) the parameters, local variables, etc. should be placed are all determined. When the program runs to the corresponding program, the stack will be operated in the compiled order.
Isn’t pushing onto the stack a process that only occurs at runtime? Compilation is just a process of translating into bytecode. Why is there pushing on the stack?
The order of pushing onto the stack is determined at compile time.
The main thing that needs to be pushed onto the stack before a function call is the function parameters, and the parameters are all fixed (the variable parameters are just offsets determined by macros).
The code for calling functions is placed in the code segment, and pushing onto the stack is done in the form of instructions, so the order is determined at compile time.
@lianera is right, the order of pushing onto the stack is determined at compile time.
Let me show you an example:
I have a piece of code like this
After compilation, his assembly code looks like this
It doesn’t matter if you don’t understand assembly. During the compilation process, the order in which parameters are passed, and where on the stack (relative position) the parameters, local variables, etc. should be placed are all determined. When the program runs to the corresponding program, the stack will be operated in the compiled order.
Isn’t pushing onto the stack a process that only occurs at runtime? Compilation is just a process of translating into bytecode. Why is there pushing on the stack?