How to avoid code duplication in a function?

scswift:

pYro_65:

I also can't use an inline function, because although the code in those is supposed to just replace the function call, the compiler can decide not to do that which means trying to call variables local to the function holding my switch statement is a no-no.

You are also using GCC in the Arduino environment, so you can use GCC function attribute 'always inline':

I would prefer not to use compiler specific things. I'm trying to get into good coding practices in C, not GCC specifically.

Well use a C compiler, you are in C++ land my friend. Even without using attributes, I have managed to get every function that I need in lined to be so, maybe a reorganisation of how you declare your functions is in order, wildbill points out a major player. The only place you will have trouble is with template functions ( newer GCC does not have problem ).

Static on a global variable makes it visible to the compilation unit it is defined in, other units cannot see it, if they can see the declaration ( if in header ) then they get their own copy.