Does 11.4 apply to any pointer or just object pointers?

Moderators: misra-c, david ward

Post Reply
rgamble
Posts: 14
Joined: Fri Jul 20, 2007 7:54 pm

Does 11.4 apply to any pointer or just object pointers?

Post by rgamble » Fri Oct 25, 2013 5:17 pm

The scope of Rule 11.4 is unclear. The headline text for Rule 11.4 uses the phrase "pointer to object", the amplification just uses "pointer", and the rationale uses both phrases. Is this rule intended to apply to pointers to functions and pointers to incomplete types? In other words, are the following violations of this rule?

Code: Select all

void *vp        = 1;
int (*fp)(void) = 1;
If the answer is "yes", then does the exception for null pointer constants (which also uses the phrase "pointer to object") apply to all pointers or just pointers to objects? E.g.:

Code: Select all

int *ip         = 0;  // Okay, allowed by exception
void *vp        = 0;  // Okay?
int (*fp)(void) = 0;  // Okay?

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

Re: Does 11.4 apply to any pointer or just object pointers?

Post by misra-c » Fri Dec 13, 2013 9:03 am

This rule only applies to object pointers, as other types of pointers are covered by other rules.

We will consider clarifying the amplification to read:
An object pointer should not be converted into an integer.
An integer should not be converted into an object pointer.

Code: Select all

       void *vp        = 1;   /* Constraint error in C90 and C99; violates rule 1.1 */
       int (*fp)(void) = 1;   /* Constraint error in C90 and C99; violates rule 1.1 */ 
  
        /* The following will all violate 11.9 */
       int *ip         = 0;  /* compliant with 11.4 exception  */
       void *vp        = 0;  /* compliant with all other section 11 rules */
       int (*fp)(void) = 0;  /* 11.4 does not apply, compliant with 11.1 exception */ 
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.11 Pointer type conversions”