MISRA Discussion Forums
Rule 14.2 and system level - 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.14 Control statement expressions (https://forum.misra.org.uk/forumdisplay.php?fid=169)
+---- Thread: Rule 14.2 and system level (/showthread.php?tid=1352)



Rule 14.2 and system level - xiangke - 14-06-2017

As We know, analysis of scope is classified as single translation unit and system.
Rule 14.2 is system analyzed scope,
In my opinion, a For loop is always placed on a function, it is a code block. a loop counter it uses has no linkage.why the analysis for it shall be dependent on the other module, can anybody give a example for explanation?
thanks very much in advance!


Re: Rule 14.2 and system level - misra-c - 21-09-2017

Code:
== file1.c ==
void fn ( int32_t *ptr )
{
   *ptr = 10;
}

== file2.c ==
extern void fn ( int32_t *ptr );  /* extern should be in header file */

void loop ( void )
{
  for ( int32_t i = 0; i < 10; i++  )
  {
    fn( &i );
  }
}
The above example is not compliant with rule 14.2 because fn assigns a value to "i" in the body of the loop. This can only be determined if the definition of fn is analysed. Therefore a system analysis containing file1.c and file2.c is required.