Is the size of a function important with respect to unused conditionals?

To clarify the title:

I have a hardware timer dependent ISR that contains a switch case. I want to add another case which calls a different set of global (volatile, of course) variables to serve a different purpose.

void timer_isr(void)
{
switch (select)
{
case 1: // code that uses a set of global variables
break;

case 2: // same globals as above, different instructions
break; 

default: // case in question: different globals, different instructions
break; 

}

I'm aware that adding additional cases itself adds to the complexity of the ISR via more cases to check, which we want to avoid doing too much of, but how important is the complexity of a function, with respect to unused code?

In my case, should I worry about having a bunch of code packed into a time-sensitive ISR, even though it's a switch case and only one case can be 'active' or 'true' at a time?

An extreme example of my question (this is not what I'm actually doing): in my time-sensitive code, what if one of the cases had a humongous code-breakingly large function inside, but by design that case was never used. Would the size of the code inside the unused case affect the functionality of the rest of the ISR?

Hope the question is clear. Thank you.

Code that does not get executed takes no time at all :slight_smile:

So no impact of what is not used (and if the compiler can decide it’s not being used like you have a if(false) {…} then it will even get rid of the code in the app once compiled

Good to know!

In my project, all of the cases will be used but none of them are code-breaking. Does that affect your response? The reason for my extreme example is more to illustrate the overall size of the ISR to see if that impacts performance, less so about a case that is never used. I should have thought of a better example!

edit:

Looked up the correct terminology of the term 'execute' which I'd previously thought meant something that happened only at compile time. Knowing now what execution is, this is a very clear answer, thank you! Much to learn :sweat_smile:

You've posted a very hypothetical question, with a made-up example. That would not be nearly as effective as posting the actual code. Especially considering your focus on efficiency. Any take aways that you get from such a general discussion may not prove nearly as useful to you.

Or, for that matter, should the functions in question even be in the ISR? Or, would they better be implemented in non-ISR code with signaling from the ISR for synchronization?

Variables, unless function pointers, are never "called"

Not sure what that means.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.