30-03-2017, 07:25 AM
This rule only applies to the type qualifiers of the type pointed to by the top-level pointer.
For example:
It is a violation of this rule to cast an object of type "X const *" to "Y *".
The presence/absence of type qualifiers within X or Y are covered by rule 11.3 and not by this rule.
For example:
Looking at the specific examplesAll these examples would violate rule 11.3
For example:
It is a violation of this rule to cast an object of type "X const *" to "Y *".
The presence/absence of type qualifiers within X or Y are covered by rule 11.3 and not by this rule.
For example:
Code:
"const int **ppci" is a "pointer to pointer to const int".
The "pointer to const int" has no type qualifiers.
"int *const *pcpi" is a "pointer to const pointer to int".
The "pointer to int" has a const type qualifier
Performing the cast "( const int**)(pcpi)" would cast away the const and violate this rule.
Looking at the specific examples
Code:
pi = (int*) &a;
Casts "ptr to array of const int" to "ptr to int".
Compliant: no top-level type qualifier removed
ppi = (int**) cppi;
Casts "ptr to ptr to const int" to "ptr to ptr to int"
Compliant: no top-level type qualifier removed
ppi = (int**) cppf;
Casts "ptr to ptr to const float" to "ptr to ptr to int"
Compliant: no top-level type qualifier removed
Posted by and on behalf of the MISRA C Working Group