For example, I have three functions: f1(), f2()and f3(). When called f1, it stores information in processor registers (and I believe that there is other important information). Now, depending on a state that is unknown at compile time, it f1will call either f2or f3. f2and f3use very different registers, some of which may overlap with those that are used f1. Is the following reasoning correct?
The compiler knows that it registers a particular function during its execution. Therefore, when it f1calls either f2, or f3, the function call code stores those registers that f2either f3use on the stack, regardless of whether they are used f1or not.
Or is there some other mechanism by which the compiler saves registers so that the returned function does not lose its data?
source
share