[previous] 3218 [next] File scope static, '%s', is only accessed in one function.
Declarations and Definitions

An object has been defined at file scope with internal linkage but it is only referenced in one function.

If the object is only going to be used in one function it may be better to define it at block scope so as to decrease its visibility and improve maintainability. Objects are sometimes defined at file scope deliberately in order to assist in debugging.

For example:


/*PRQA S 2017,3408 ++*/

static int x1 = 0;                      /* Message 3218 */

extern void f1(void)
{
}

extern void f2(void)
{
    static int x2 = 0;                  /* Message 3223 */

    ++x1;
    ++x2;
}


MISRA C:2012 Rules applicable to message 3218:

Rule-8.9  (Advisory) An object should be defined at block scope if its identifier only appears in a single function


See also:

QA·C Source Code Analyser 8.1
MISRA C:2012 Compliance Module 1.0
© 2012 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index Contents