MISRA Discussion Forums
Does rule #15.3 apply to all blocks or only control blocks? - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21)
+---- Forum: 8.15 Control flow (https://forum.misra.org.uk/forumdisplay.php?fid=170)
+---- Thread: Does rule #15.3 apply to all blocks or only control blocks? (/showthread.php?tid=956)



Does rule #15.3 apply to all blocks or only control blocks? - gs - 09-04-2013

Suppose I have the following code:
Code:
void f()
{
    {
    goto L1;
    }
    {
L1:
    }
}

Does this code violate rule #15.3?


Re: Does rule #15.3 apply to all blocks or only control bloc - misra-c - 01-07-2013

The Rule states that the label and the goto "shall be declared in the same block, or in any block enclosing the goto statement"

This rule applies to any block, not just control blocks.

The example cited is NON-COMPLIANT as label L1 is in a parallel block, not a block enclosing the goto.

Code:
void f()
{
    {
    goto L1;
    }
    {
L1:   /* Non-compliant */
    }
}