Home > Software design >  How to do I solve rule 8.7 MISRA-C?
How to do I solve rule 8.7 MISRA-C?

Time:10-06

misra_c_2012_rule_8_7_violation

Function "cpvqResponse" has external linkage but is only used in one translation unit.

CodePudding user response:

This means that functions that aren't exposed outside one particular .c file but only used in that file must be declared static. Which is a perfectly sensible thing to do in all C programs, regardless of MISRA-C.

CodePudding user response:

Putting together all the comments, I understand that your code is something like this:

library.c

void cpvqResponse( void )
{
    ...
}

library.h

extern void cpvqResponse( void );

project.c

   void main( void )
   {
       ...
       cpvqResponse();
       ...
   }

MISRA C:2012 Rule 8.7 is an Advisory Guideline, and aims to enhance the cohesion of, and reduce coupling between, your translation units.

As outlined in MISRA Compliance, there are times and places where the MISRA Guidelines may be inappropriate, and there are mechanisms in place.

As it is Advisory, possible mitigations are:

  1. Move the code - possible if project code, but not if adopted code
  2. Just ignore the Rule - this is contrary to MISRA Compliance
  3. Disapply the Rule, with rationale, eg code modularity - this is often the correct approach

As I have said before, anyone who demands 100% MISRA Compliance, with no deviations (or disapplication) hasn't read, or understood, the guidance.

[See profile for affiliation]

  • Related