[previous] MISRA-C:2004  Rule  11.1:  (Required) [next] Conversions shall not be performed between a pointer to a function and any type other than an integral type.
Conversion of a function pointer to a different type of pointer results in undefined behaviour. This means that a function pointer can be converted to or from an integral type. No other conversions involving function pointers are permitted.

Example Code:


/* PRQA S 2983 ++ */


#include "misra.h"
#include "m2cmex.h"

typedef S32  ( *pif1 )( void );
typedef S16  ( *pif2 )( void );

extern S16 test_1101( void )
{
   pif1 pif32a = 0;
   pif2 pif16a;
   S32 *pi;

   f64a   = (F64)pif32a;              /* MISRA Violation */
   pif32a = (pif1)f64a;               /* MISRA Violation */

   pi     = (S32 *)pif32a;            /* MISRA Violation */
   pif32a = (pif1)pi;                 /* MISRA Violation */

   pif16a = (pif2)pif32a;             /* MISRA Violation */
   pif32a = (pif1)pif16a;             /* MISRA Violation */

   return 1;
}


QAC messages that encompass this guideline:

0302 [u] Cast between a pointer to function and a floating type.
0307 [u] Cast between a pointer to object and a pointer to function.
0313 Casting to different function pointer type.


Related rules:

Rule  1.2 No reliance shall be placed on undefined or unspecified behaviour.



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