We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
MISRA stands for "Motor Industry Software Reliability Association". IAR has an Embedded Workbench which I believe is a Tester to verify the implementation for the MISRA C rules.
Does KEIL have a such a tool?
If there a PDF document available that spells out the rules. I have search and all I can find are test suites.
goto really is useful in some situations.
However, all usage should be very similar to the usage of break and continue, but with the ability to make it multi-level, i.e. to break out of (or restart) more than one encapsulation.
You might have a function:
void fnk(void) { restart: do_something(); for (;;) { do_more(); switch (x) { case 1: if (error) goto fail; do_work(); break; case 10: do_even_more(); break; default: goto restart; } } fail: do_cleanup(); }
Yes, it is possible to solve all flow problems with flags, a large set of conditionals, and optional extra loops, but there comes a point where these flags gets very hard to read. The code must check if it should leave (or restart) first level, then second level, ...
"... but there comes a point where these flags gets very hard to read."
And thus become a potential source of errors themselves when the logic they control is not obvious.
And that's the problem I see about the MISRA ruleset. It is not intended to reduce errors, but to eliminate ambiguities and implementation-specific behavior of C - even at the cost of introducing additional sources of errors and degrading performance significantly.