MISRA.FUNC.ADDRAddress of a function is used without & operator. MISRA-C Rule 16.9 (required): A function identifier shall only be used with either a preceding '&', or with a parenthesised parameter list, which may be empty.[Koenig 24] If the programmer writes: if (f) /* not compliant - gives a constant non-zero value which is the address of f - use either f() or &f */ { /* ... */ } then it is not clear if the intent is to test if the address of the function is not NULL or that a call to the function 'f()' should be made. MISRA-C++ Rule 8-4-4 (required): A function identifier shall either be used to call the function or it shall be preceded by '&'.RationaleA function identifier can implicitly convert to a pointer to a function. In certain contexts this may result in a well-formed program, but which is contrary to developer expectations. For example, if the developer writes:
then it is not clear whether the intent is to test if the address of the function is NULL or if a call to the function 'f()' should be made and the brackets have been unintentionally omitted. The use of the '& (address-of)' operator will resolve this ambiguity. ExceptionPassing the function by reference, or assigning it to a reference object is not a violation of this rule. Exampleextern void f ( void ); if ( 0 == f ) // Non-compliant { // ... } void (*p)( void ) = f; // Non-compliant if ( 0 == &f ) // Compliant { (f)(); // Compliant as function is called } void (*p)( void ) = &f; // Compliant |