[C-safe-secure-studygroup] reformulation of rule 15.2 - goto shall jump to a label declared later

Martin Sebor msebor at gmail.com
Wed Jun 13 15:13:26 BST 2018


In my last review of rule Rule 15.2 - The goto statement shall
jump to a label declared later in the same function, I suggested
that...

   Rather than seemingly arbitrarily restricting the direction of
   goto statements I wonder if focusing the rule on the problem
   it seems to want to prevent would be a better way to formulate
   it.

As explained in the Rationale, the goal of the rule is to

   ensure that iteration only occurs if the iteration statements
   provided by the language are used, helping to minimize visual
   code complexity.

So as my homework assignment I tried to reformulate the rule along
these lines.

   New Rule - goto statements shall not be used for iteration

   Within the body of an iteration statement (C11 6.8.5) control
   shall pass through each goto statement at most once in each
   iteration.

   Outside the body of an iteration statement control shall pass
   through each goto statement at most once in each invocation
   of the function it appears in.

The two restrictions prevent using goto for iteration without
restricting the direction of jumps, in closer alignment with
the rule's objective.

Martin



More information about the C-safe-secure-studygroup mailing list