Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Violation of Rule 11.4 or Rule 11.5?
#4
The final statement in the example code for 11.5 is misleading.
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   */
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.
Posted by and on behalf of the MISRA C Working Group
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)