MISRA.FUNC.STATIC.REDECLFunction or object redeclaration does not include static modifier
MISRA C 2012 Rule 8.8: The static storage class specifier shall be used in all declarations of objects and functions that have internal linkageCategory: Required Analysis: Decidable, Single Translation Unit Applies to: C90, C99 AmplificationSince definitions are also declarations, this rule applies equally to definitions. RationaleThe Standard states that if an object or function is declared with the extern storage class specifier and another declaration of the object or function is already visible, the linkage is that specified by the earlier declaration. This can be confusing because it might be expected that the extern storage class specifier creates external linkage. The static storage class specifier shall therefore be consistently applied to objects and functions with internal linkage. Examplestatic int32_t x = 0; /* definition: internal linkage */ extern int32_t x; /* Non-compliant */ static int32_t f ( void ); /* declaration: inte rnal linkage */ int32_t f ( void ) /* Non-compliant */ { return 1; } static int32_t g ( void ); /* declaration: internal linkage */ extern int32_t g ( void ) /* Non-compliant */ { return 1; } MISRA-C 2004 Rule 8.11 (required): The static storage class specifier shall be used in definitions and declarations of objects and functions that have internal linkageFunction or object redeclaration does not include 'static' modifier. The static and extern storage class specifiers can be a source of confusion. It is good practice to apply the static keyword consistently to all declarations of objects and functions with internal linkage. MISRA-C++ 2008 Rule 3-3-2 (required): If a function has internal linkage then all redeclarations shall include the static storage class specifier.RationaleIf the declaration of a function includes the static storage class specifier, then it has internal linkage. A re-declaration of such a function is not required to have the static keyword, but it will still have internal linkage. However, this is implicit and may not be obvious to a developer. It is therefore good practice to apply the static keyword consistently so that the linkage is explicitly stated. Examplestatic void f1 ( ); static void f2 ( ); void f1 ( ) { } // Non-compliant static void f2 ( ) { } // Compliant |