Suppose I have an arbitrary function:
void someFunc(int, double, char);
and I call someFunc(8, 2.4, 'a');, what actually happens? How does 8, 2.4, and ‘a’ get memory, moved into that memory, and passed into the function? What type of optimizations does the compiler have for situations like these? What if I mix and match parameters, such like someFunc(myIntVar, 2.4, someChar);?
What happens if the function is declared as inline?
It makes no difference that the values are literal or not (unless the function is inlined and then the compiler can optimize some stuff out).
Usually, parameters are put into registers or the function parameter stack. Regardless of whether they are explicit values or variables.
Without optimizations, the parameter gets pushed onto the parameter stack. In the first case, the value of
xis taken first and put into registereax, then pushed into the parameter stack.fooprintsx.With optimizations the function is visible to the compiler (in my sample) and the call is skipped altogether:
foois defined as: