Rule 14.2 and system level

Moderators: misra-c, david ward

Post Reply
xiangke
Posts: 9
Joined: Tue Apr 11, 2017 7:34 am
Company: valeo

Rule 14.2 and system level

Post by xiangke » Wed Jun 14, 2017 10:13 am

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!

misra-c
Posts: 556
Joined: Thu Jan 05, 2006 1:11 pm

Re: Rule 14.2 and system level

Post by misra-c » Thu Sep 21, 2017 11:16 am

Code: Select all

== 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.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.14 Control statement expressions”