Rule 11.1, 11.2 (and others?) vs conversion caused by equality operators (and similar)?

Moderators: misra-c, david ward

Post Reply
pkruk
Posts: 20
Joined: Fri Jul 27, 2007 3:25 pm

Rule 11.1, 11.2 (and others?) vs conversion caused by equality operators (and similar)?

Post by pkruk » Wed Jun 03, 2015 3:14 pm

Hello,

rules 11.1 and 11.2 disallow conversions between pointer to a function or incomplete type, and any other type:

Code: Select all

void (*fp1)(short);
void (*fp2)(int);

fp2 = fp1;          /* Not-compliant - different function */
fp2 = 0x8000;       /* Not-compliant - integer */
What if the conversion happens for example in equality operator:

Code: Select all

fp2 == fp1;         /* Compliant or Not-compliant ? */
fp2 != 0x8000;      /* Compliant or Not-compliant ? */
Following example from Rule 11.1 suggests it's also non-compliant:

Code: Select all

if ( fp2 != NULL )  /* Compliant - exception 1 (NULL) */

misra-c
Posts: 560
Joined: Thu Jan 05, 2006 1:11 pm

Re: Rule 11.1, 11.2 (and others?) vs conversion caused by equality operators (and similar)?

Post by misra-c » Thu Jun 25, 2015 8:36 am

The rules in section 11 cover the implicit and explicit conversions that are permitted by the C standard. It does not matter whether these conversions occurring in an assigning context ( fp2 = fp1 ) or a balancing context ( fp2 == fp1 ).

Therefore the compliance of your examples are as follows:

Code: Select all

fp2 == fp1;         /* Not-compliant */
fp2 != 0x8000;      /* Not-compliant  */
if ( fp2 != NULL )  /* Compliant - exception 1 on NULL */
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.11 Pointer type conversions”