I'm trying to understand the concept of inline functions versus regular functions and got stuck on the term 'function overhead.' In regular functions in C, I understand the stack memory allocation and release when a function is called and exits. For instance, we can have a function that take argument, increments a value, and doesn't return.
What do you mean "doesn't return"? It's not a function if it doesn't return.
If you have a C function such as ...
int inc(int i) {
return i + 1;
}
... then a decent modern ISA such as RISC-V or Arm (either 32 bit or 64 bit) will have two instructions in the function:
inc:
add a0,a0,1
ret
It takes one instruction to call the function, and one to return, so you could say the overhead is two instructions. It might take several clock cycles for each of those control flow changes on a simple CPU, or just one cycle on one with instruction cache and/or branch target cache. Mid-range CPUs and up (Arm A53, SiFive U74, Intel Pentium, PowerPC 601/603) will execute both the add and ret in the same clock cycle.
If the instruction set is such that the return address must be written to RAM and then read back on returning then that adds more overhead. So do instruction sets (e.g. VAX CALLS/CALLG) or ABIs that require setting up and tearing down a stack frame even for trivial functions.
There is also overhead in the calling function to consider. You may need to copy the function argument to the correct register (or worse, push it on to the stack) and copy the result somewhere else to preserve it before the next function call. Both of those are not necessary if the function is inlined.
Even worse, if this is the only function call made by the caller, then this may force the caller to set up a stack frame, and save and restore the return address and other registers.