Skip to main content

IAR Embedded Workbench for Arm 9.70.x

MISRAC2004-11.4

In this section:
Synopsis

(Advisory) A cast should not be performed between a pointer to object type and a different pointer to object type.

Enabled by default

No

Severity/Certainty

Low/Medium

lowmedium.png
Full description

A pointer to object type was found that is cast to a pointer to different object type. This check is identical to MISRAC++2008-5-2-7.

Coding standards
MISRA C:2004 11.4

(Advisory) A cast should not be performed between a pointer to object type and a different pointer to object type.

MISRA C++ 2008 5-2-7

(Required) An object with pointer type shall not be converted to an unrelated pointer type, either directly or indirectly.

Code examples

The following code example fails the check and will give a warning:

typedef unsigned int uint32_t;
typedef unsigned char uint8_t;

void example(void) {
	uint8_t * p1;
	uint32_t * p2;
	p2 = (uint32_t *)p1;
}

The following code example passes the check and will not give a warning about this issue:

typedef unsigned int uint32_t;
typedef unsigned char uint8_t;

void example(void) {
	uint8_t * p1;
	uint8_t * p2;
	p2 = (uint8_t *)p1;
}