Created
November 14, 2012 06:14
-
-
Save thomo/4070617 to your computer and use it in GitHub Desktop.
Coding Horror: do while with goto instead of break
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function(parameters){ | |
Boolean found = false; | |
do{ | |
for(counter){ | |
such etwas in einem Array | |
if(bedingung) { | |
found = true; | |
goto do_end | |
} | |
} | |
if(bedingung){ | |
found = true; | |
goto do_end; | |
} | |
do_end: | |
; | |
} while(0) | |
if(found) return wert | |
else wert_unbekannt | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Motivation:
-> höhere Performance durch Überspringen von zur Laufzeit nicht länger benötigten Anweisungen
-> Erfüllung von MISRA 14.7: A function shall have a single point of exit at the end of the function.
Mittel:
-> frühzeitiges Abbrechen von Schleifen
-> Direktsprünge zu Anweisungen
Auswirkung:
-> Verletzung von MISRA 14.6: For any iteration statement there shall be at most one break statement used for loop termination.
-> Verletzung von MISRA 14.4: The goto statement shall not be used.
Frage:
Wieviele Anweisungen muss man sparen, um eine der beiden Regeln (MISRA 14.6 oder MISRA 14.7) verletzen zu dürfen?