![]() |
|
MISRA C:2012 Rule-11.4: (Advisory) |
|
||||
![]() | |||||||
Amplification:
A pointer should not be converted into an integer.
An integer should not be converted into a pointer.
Exception:
A null pointer constant that has integer type may be converted into a pointer to object.
Example Code:
#pragma PRQA_MESSAGES_OFF 1056,2982,3210,3408,3447
#include "misra.h"
#include "m3cmex.h"
extern volatile uint16_t * pvui;
extern uint16_t * puim;
extern int16_t rule_1104 ( void )
{
volatile uint16_t vui = uib;
pvui = (volatile uint16_t *) 0x1234U; /* 0303 */
pvui = (volatile uint16_t *) vui; /* 0303 */
puim = (uint16_t *) 0x1234U; /* 0306 */
puim = (uint16_t *) uia; /* 0306 */
puim = (uint16_t *) bla; /* 0362 */
bla = puim; /* 0360 */
bla = (_Bool)puim; /* 0361 */
ula = (uint32_t)pvui; /* 0303 */
ula = (uint32_t)puim; /* 0306 */
return 0;
}
QAC messages that encompass this guideline:
| 0303 | [I] Cast between a pointer to volatile object and an integral type. |
| 0306 | [I] Cast between a pointer to object and an integral type. |
| 0360 | An expression of pointer type is being converted to type _Bool on assignment. |
| 0361 | An expression of pointer type is being cast to type _Bool. |
| 0362 | An expression of essentially Boolean type is being cast to a pointer. |
Related rules:
| Rule-11.6 | A cast shall not be performed between pointer to void and an arithmetic 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 |