If a bit of code duplication doesn't bother you (and you have cvar callbacks), a global function pointer is better than a global int. Then the cvar can select the appropriate function. If you don't have callbacks, then checking the global (or cvar) before calling the function is almost as good. The less branches in your inner loop, the better (but certainly, don't go checking global vars, or worse, cvars!).
Also, if your compiler is good with inline functions, you can put most of the logic into a set of such and then the separate functions selected by the cvar are just a series of inlined calls to the functions, with the calls for the selectable functionality different.
eg: (functions selected by if for simplicity)
Code: Select all
static inline void func1() {...}
static inline void func2a() {...}
static inline void func2b() {...}
static inline void func3() {...}
void func_a ()
{
while (condition) {
func1();
func2a();
func3();
}
}
void func_b ()
{
while (condition) {
func1();
func2b();
func3();
}
}
void func()
{
if (cvar) func_a();
else func_b();
}