AutosarC++18_10-M8.4.4¶
A function identifier shall either be used to call the function or it shall be preceded by &
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
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
Note
For legal reasons, this rule’s description is not part of the public documentation.