24-04-2018, 09:41 AM
Rule 21.15 applies to the types after casting.
Code:
void f(signed char* a, int* b, size_t n) {
memcmp(a, a, n); // Compliant
memcmp(b, b, n); // Compliant
memcmp((int*)b, (int*)b, n); // Compliant
memcmp((int*)a, (int*)a, n); // Compliant - but violates Rule 11.3
memcmp(a, b, n); // Non-Compliant
memcmp((int*)a, b, n); // Compliant - but violates Rule 11.3
memcmp((float*)a, (float*)b, n); // Compliant - but violates Rules 11.3 and 21.16
memcmp((short*)a, a, n); // Non-Compliant - and also violates Rule 11.3
}
Posted by and on behalf of the MISRA C Working Group