MISRAC2012-Rule-8.7
Synopsis
(Advisory) Functions and objects should not be defined with external linkage if they are referenced in only one translation unit.
Enabled by default
No
Severity/Certainty
Low/Medium

Full description
An externally linked object or function was found referenced in only one translation unit. This check is identical to MISRAC2004-8.10.
This is a link analysis check.
Coding standards
- MISRA C:2004 8.10
(Required) All declarations and definitions of objects or functions at file scope shall have internal linkage unless external linkage is required.
- MISRA C:2012 Rule-8.7
(Advisory) Functions and objects should not be defined with external linkage if they are referenced in only one translation unit
Code examples
The following code example fails the check and will give a warning:
/* file1.c
static void example (void) {
// dummy function
}
*/
/* extern linkage */
extern int x;
/* static linkage */
static void foo(void) {
/* only referenced here */
x = 1;
}
The following code example passes the check and will not give a warning about this issue:
/* static linkage */
static int x;
/* static linkage */
static void foo(void) {
/* no linkage */
int y = (x++);
if(y < 10)
foo();
}