Answer the question
In order to leave comments, you need to log in
Explain rules 57 and 58 in MISRA C. Why are break, continue bad?
Came across the MISRA C standard which states:
Rule 57 (required): The continue statement shall not be used.
Rule 58 (required): The break statement shall not be used (except to terminate the cases of switch statement.
Answer the question
In order to leave comments, you need to log in
Nonsense from the category "goto is bad". For small controllers, goto is very normal. And in the processing of KA and any conditions, break, continue, goto are simply necessary ...
programmers.stackexchange.com/questions/58237/are-...
They make multiple block exit points.
Usually they are used to reduce the nesting of conditions in a block, and for good it is necessary to rewrite the code so that there is less nesting.
Their use is to mask such situations so that the code does not look bad. And masking bad code is bad.
The only reasonable answer that I saw is that if in the block (loop body) someone wants to write malloc, and at the end - free (or, for example, fopen / fclose), and does not notice that there is break or continue, then problems can arise.
And in the 2004 standard, the ban on break was weakened. The ban on goto and continue was left.
Because break and continue are variants of goto, and goto violates the principles of structured programming .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question