[previous] MISRA-C:2004  Rule  8.10:  (Required) [next] All declarations and definitions of objects or functions at file scope shall have internal linkage unless external linkage is required.
If a variable is only to be used by functions within the same file then use static. Similarly if a function is only called from elsewhere within the same file, use static. Use of the static storage-class specifier will ensure that the identifier is only visible in the file in which it is declared and avoids any possibility of confusion with an identical identifier in another file or a library.

Example Code:


/* PRQA S 3408 ++ */

#include "misra.h"
#include "m2cmex.h"

S16 obj_0810a;
S16 obj_0810b;

static S16 test_0810b( void );

extern S16 test_0810( void )
{
   S16 r;

   r = test_0810a() + test_0810b();

   return r;
}

extern S16 test_0810a( void )
{
   return obj_0810a;
}

static S16 test_0810b( void )
{
    return obj_0810b;
}


QAC messages that encompass this guideline:

1504 The object '%1s' is only referenced in the translation unit where it is defined.
1505 The function '%1s' is only referenced in the translation unit where it is defined.



(c) The Motor Industry Research Association, 2004
QA C Source Code Analyser 8.1.2
MISRA-C:2004 Compliance Module 3.2
© 2013 Programming Research
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index Contents