06-04-2017, 01:55 PM
Code:
static void use_array(uint8_t const (* const arr)[4])
{
}
int main()
{
uint8_t aAction[4] = {0, 0, 0, 0};
use_array((uint8_t const(*)[4]) &aAction); // 11.3 violation?
}
As I read rule 11.3, the cast in the use_array call violates rule 11.3: the target type of the pointer is "4-element array of const uint8_t". Given that the "const" is not at top-level, adding it is not permitted by this rule.
However, that raises the question: how can I call use_array() from Misra-compliant code?
Note that the cast is required by ISO C (gcc says: pointers to arrays with different qualifiers are incompatible in ISO C [-Wpedantic]).
However, in C++, an implicit conversion exists for this case.
<t></t>