I remember reading a question a user had about handling interrupts, he didn't like the fact that he would need to create global state variables in order to implement handling them as state machines (a purest after my own heart). I couldn't re-locate the discussion to add my thoughts there.
My way around that is to create a class for each set of variables and functions needed, created at compile time (i.e., not using "new"). Now the "global" variables are encapsulated in the private section of the class. For example:
class BiasClass {
private:
int StateVariable;
...
public:
void SetVoltage(int Voltage);
void RunPidLoop(void);
...
};
// Declare non-inline functions here ...
// Declare 1 instance of class
BiasClass Bias;
// Now call functions
Bias.SetVoltage(Voltage);
// The timer interrupt calls:
Bias.RunPidLoop();
I haven't looked at the resulting assembly code but I bet that other than very slightly more startup time from the call to the constructor it's about the same efficiency as doing it in C.
Doug