Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

MISRA.FUNC.ADDR

Address 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 '&'.

Rationale

A 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:

if ( f )

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.

Exception

Passing the function by reference, or assigning it to a reference object is not a violation of this rule.

Example

extern 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