Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rationale for no goto, continue but allow break
#4
niall Wrote:I know this should have been brought up before, but in reviewing MISRA-2 this passed me by.
Being pedantic, why has the rule on break (14.6) been relaxed and not 14.5 (or 14.4)?
A break in a loop is just a goto!
I have no problem with it, it just smacks of inconsistency.

I seem to recall griping about this at the first MISRA-C forum thing (many years ago). I thought that disallowing break within a loop was extreme and that the alternatives (largely loop control variables) are ugly and error prone; others (Peter Amey I suspect) pointed out that it was a stronger restriction than that in SPARK Ada (which allows, if I remember correctly, a break from a top level conditional within a loop). This may have influenced the decision.

As an aside, we could, of course, rewrite all control flow in terms of if/goto (compilers do it all the time) -- there isn't anything special about break. (See http://david.tribble.com/text/goto.html for interesting discussion on modern goto thinking.)


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)