07-04-2009, 07:28 PM
The final statement in the example code for 11.5 is misleading.
It is, in fact, a violation of Rule 11.4.
A pointer which addresses a "pointer to uint16_t" and a pointer which addresses a "pointer to const uint16_t" are pointers which address identically qualified versions of different types. A pointer which addresses a "pointer to uint16_t" and a pointer which addresses a "const pointer to uint16_t" are pointers which address differently qualified versions of identical types.
It is, in fact, a violation of Rule 11.4.
Code:
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 - Rule 11.5 */
pi = (uint16_t *)pvi; /* Not compliant - Rule 11.5 */
ppi = (uint16_t * *)pcpi; /* Not compliant - Rule 11.5 */
ppi = (uint16_t * *)ppci; /* Not compliant - Rule 11.4 */
Posted by and on behalf of the MISRA C Working Group