[previous] MISRA C:2012  Rule-11.2:  (Required) [next] Conversions shall not be performed between a pointer to an incomplete type and any other type

Amplification:

A pointer to an incomplete type shall not be converted into another type.

A conversion shall not be made into a pointer to incomplete type.

Although a pointer to void is also a pointer to an incomplete type, this rule does not apply to pointers to void as they are covered by Rule-11.5.

Exception:

  1. A null pointer constant may be converted into a pointer to an incomplete type.
  2. A pointer to an incomplete type may be converted into void.

Example Code:


#pragma PRQA_MESSAGES_OFF 3112,3408,3447

#include "misra.h"
#include "m3cmex.h"

extern struct S1102 *ps1102;
extern struct T1102 *pt1102;

extern int16_t rule_1102( void )
{
    int16_t *pi = &s16a;

/****************************************
CASTING FROM A POINTER TO INCOMPLETE TYPE
****************************************/
    (int16_t *)  ps1102;                       /* 0308      0310 */        /* Non-compliant */
    (struct t *) ps1102;                       /* 0308      0310 */        /* Non-compliant */


/****************************************
CASTING TO A POINTER TO INCOMPLETE TYPE
****************************************/
    (struct S1102 *)0x1234u;                   /*      0306      */        /* Non-compliant */
    (struct S1102 *)pi;                        /* 0308      0310 */        /* Non-compliant */
    (struct S1102 *)pt1102;                    /* 0308      0310 */        /* Non-compliant */

    return 0;
}


QAC messages that encompass this guideline:

0308 Non-portable cast involving pointer to an incomplete type.



(c) The Motor Industry Research Association, 2012
QA C Source Code Analyser 8.1.2
MISRA C:2012 Compliance Module 1.0
© 2013 Programming Research
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index Contents