Main Content

MISRA C:2023 Rule 17.12

A function identifier should only be used with either a preceding &, or with a parenthesized parameter list

Since R2024a

Description

Rule Definition

A function identifier should only be used with either a preceding &, or with a parenthesized parameter list.

Rationale

Using a function identifier without a preceding & or a following parenthesized parameter list is confusing. It is not clear whether the intent is to call a function or to obtain the address of the function.

Polyspace Implementation

This rule checker reports a violation if a function identifier is used without either of these:

  • A preceding &

  • A following parenthesized parameter list

Troubleshooting

If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.

Examples

expand all

In this example, the function identifier func is used without a preceding & or a following set of parenthesis. The rule checker reports violations for these ambiguous uses.

#include <stdint.h>

typedef int32_t (*func_ptr_i)(void);
extern int32_t func1(void);        /* Note: A function */
extern int32_t (*func2)(void);     /* Note: A function pointer */
void func(void)
{
	func_ptr_i pfn1 = &func1;       /*Compliant*/
	func_ptr_i pfn2 = func1;        /*Noncompliant*/
	pfn1();                    /*Compliant*/

	if(func1 == func2)         /*Noncompliant*/
	{
		/* ... */
	}
	if(func1() == func2())           /*Compliant*/
	{
		/* ... */
	}

}

Check Information

Group: Functions
Category: Advisory
AGC Category: Advisory

Version History

Introduced in R2024a