Skip to content

Instantly share code, notes, and snippets.

@thomo
Created November 14, 2012 06:14
Show Gist options
  • Save thomo/4070617 to your computer and use it in GitHub Desktop.
Save thomo/4070617 to your computer and use it in GitHub Desktop.
Coding Horror: do while with goto instead of break
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
}
@oleglebov
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment