A
A
Anton2015-11-26 17:51:34
Microcontrollers
Anton, 2015-11-26 17:51:34

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.

I have not seen this in any other requirements for writing code. What is the reason for this? There are no explanations in the document itself.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
E
Eddy_Em, 2015-11-26
@Eddy_Em

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 ...

O
OnYourLips, 2015-11-26
@OnYourLips

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.

M
Mrrl, 2015-11-26
@Mrl

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.

S
Stanislav Makarov, 2015-11-26
@Nipheris

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 question

Ask a Question

731 491 924 answers to any question