Where electronics enthusiasts find answers.
sdisselhorst wrote:What command will stop the ISR and return to the main loop?In most dialects of C, you code nothing special. The compiler knows you declared the function as an ISR. It generates the correct code to restore used registers and pop the PC from the stack. Your ISR code must do the right thing to clear the interrupt cause, or there will be another immediate interrupt (a loop).
sdisselhorst wrote:What I needed was a way to stop the ISR before it reached the end. Thanks!use
if (condition) {
code here
}
else {
more code
}
}
} // end of ISR
return;
stevech wrote:UsingWhy is that? Is that because return statements are effectively branch statements and you don't want to the program to get messy? Or is it something to do with processing time and how long you want to stay in the interrupt. Or did I totally miss the point.Code: Select allat several places in the ISR is not good form.return;
rrpilot wrote:Its just a coding standard that people claim makes code more readable but I highly disagree and think multiply returns is far more easy to follow.Multiple return in many portion of code means:
- poor conceptionIf you get a coder that writes messy code you are going to have these issues regardless. Every instance that is necessary to bail out of the function your going to need to surround your code with if..then..else statements. Now all is fine and dandy when you only have 1 or 2 conditions but even 2 if..then..else blocks starts to get messy. In my opinion it all comes down to organizing your code and using comments to explain flow.
- good conception but bad coding
- hard to debug
- hard to read for a majority of people
- impossible to modify without unwanted side effects.
rrpilot wrote:Multiple return() statements in one function makes code hard to debug. Quite like goto's. I use both, very sparingly. I prefer, in a deeply nested situation, to use a goto labelxx instead of a return(), as a rule. Usually the goto is due to an unexpected condition.- poor conceptionIf you get a coder that writes messy code you are going to have these issues regardless. Every instance that is necessary to bail out of the function your going to need to surround your code with if..then..else statements. Now all is fine and dandy when you only have 1 or 2 conditions but even 2 if..then..else blocks starts to get messy. In my opinion it all comes down to organizing your code and using comments to explain flow.
- good conception but bad coding
- hard to debug
- hard to read for a majority of people
- impossible to modify without unwanted side effects.
I don't mean to highjack this thread so I'll stop there, it just cheeses me off when people say that if you use multiple returns your code is bad.