[C-safe-secure-studygroup] Rule 15.2 review - goto must jump to a label declared later

Fulvio Baccaglini fulvio_baccaglini at prqa.com
Mon Jun 4 09:55:35 BST 2018


On the subject of allowing backward jumps if they do not lead to an
iteration, I have been trying this exercise, to get a feeling: produce a
minimal (i.e. "cannot make it any more readable than this") form of a
backward jump without iteration, and then transform it to an equivalent
minimal form without backward jump. This is what I can come up with:

void f1 (bool b)
{
  if (b)
  {
    L:
    g1 ();
    return;
  }
  g2 ();
  goto L: // backward jump violates Rule 15.2
}

void f2 (bool b)
{
  if (not b)
  {
    g2 ();
  }
  g1 ();
}

The second form looks much more readable to me.

This suggests a general transformation where the block being jumped into
is dragged down, and then the jump, the label, and the control
instruction that marks the end of the block can be removed.

Can a counter-example be conceived where this transformation does not
apply, or where a backward jump form is more readable or even just as
readable?

Fulvio
---------------------------------------------------------------------------------------
 This email has been scanned for email related threats and delivered safely by Mimecast.
 For more information please visit http://www.mimecast.com
---------------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.trustable.io/pipermail/c-safe-secure-studygroup/attachments/20180604/d172e4f2/attachment.html>


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