Timeline for answer to Why "continue" is considered as a C violation in MISRA C:2004? by Kerrek SB
Current License: CC BY-SA 3.0
Post Revisions
8 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jun 11, 2012 at 8:24 | comment | added | Lance |
I found a piece of answer from MISRA Bullet Board: MISRA C Steering " In writing MISRA-C:2004, the use of a loop with two exits was considered acceptable. One is available for normal exit, and the second for exceptional exits". continue makes loop's logic complex because it changes the logic inside loop body.
|
|
| Jun 11, 2012 at 8:16 | vote | accept | Lance | ||
| Jun 15, 2012 at 2:22 | |||||
| Jun 11, 2012 at 7:58 | comment | added | Mitch Wheat | Actually, I think its better to write tests....I'm certainly not advocating that terse 'clever' code is good. Far from it. I prefer simple clean code. The point I was trying (poorly) to make is that saying you can't use 'continue' or 'break' is not productive, and may in fact lead to 'dirtier' code. It's treating the symptoms and not the cause. | |
| Jun 11, 2012 at 7:55 | comment | added | Kerrek SB | @MitchWheat: And understandably so. It's much more economical to test a large codebase for a simple rule than to get an expert consult on every single instance where a programmer was "clever enough" to write correct code. It's a classical trade-off. It may be unpleasant for the clever programmer, but in the big picture it's possible that that's the most productive solution... | |
| Jun 11, 2012 at 7:53 | comment | added | Mitch Wheat | Pointless: From experience, coding standards like their's are often dumbed down for the lowest common denominator. I use continue in C/C++/C# It is a perfectly good construct. | |
| Jun 11, 2012 at 7:50 | comment | added | Kerrek SB |
@MitchWheat: Yeah. You should lobby MISRA to add a "no long loops" rule! (But personally, in C++, I find it very hand say to be able to skip comment lines when parsing input with a simple continue. Then again, C++ is a much more suitable language for the "early exit" idiom.)
|
|
| Jun 11, 2012 at 7:19 | comment | added | Mitch Wheat | IMO, if continue makes a loop hard to understand, then the loop code is too long.... | |
| Jun 11, 2012 at 7:13 | history | answered | Kerrek SB | CC BY-SA 3.0 |