[previous] MISRA-C:2004  Rule  11.5:  (Required) [next] A cast shall not be performed that removes any const or volatile qualification from the type addressed by a pointer.
Any attempt to remove the qualification associated with the addressed type by using casting is a violation of the principle of type qualification. Notice that the qualification referred to here is not the same as any qualification that may be applied to the pointer itself.

uint16_t                 x;
uint16_t * const         cpi = &x;     /* const pointer               */
uint16_t * const       * pcpi;         /* pointer to const pointer    */
const uint16_t *       * ppci;         /* pointer to pointer to const */
uint16_t *             * ppi;	         
const uint16_t         * pci;          /* pointer to const            */
volatile uint16_t      * pvi;          /* pointer to volatile         */
uint16_t               * pi;	         
...				         
pi = cpi;                              /* Compliant - no conversion
                                          no cast required            */
pi  = ( uint16_t * )pci;               /* Not compliant               */
pi  = ( uint16_t * )pvi;               /* Not compliant               */
ppi = ( uint16_t * * )pcpi;            /* Not compliant               */
ppi = ( uint16_t * * )ppci;            /* Not compliant               */


QAC messages that encompass this guideline:

0311 Dangerous pointer cast results in loss of const qualification.
0312 Dangerous pointer cast results in loss of volatile qualification.



(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