How to resolve this MISRA c++ compliant warning

c++

Solution

First thing to note is that `int foo(const uint8_t array[])` is equivalent to int `foo(const uint8_t* array)`, i.e. the function takes a pointer to a `const uint8_t`, not an array. The pointer itself it not `const`, the pointee is. The signature should be:

int foo(const uint8_t* const array)  

For the record, I don't find this warning particularly useful. The parameter is taken by value and the caller couldn't care less what the function does with it. Furthermore, top level const qualifiers on parameters are ignored when comparing function signatures, and this can lead to some confusion.

`void foo(int)` and `void foo(const int)`, for example, are identical signatures.

EDIT:

So, according to your comment, MISRA doesn't know that you can't pass arrays by value and complains that array indexing works differently than pointer arithmetic. Shudder... The problem is that you can't add top level `const` using the array syntax, which makes fixes to these two warnings mutualy exclusive.

Try tricking it like this, then:

typedef const uint8_t Array[];
int foo(const Array arr);

Problem

``` int foo(const uint8_t array[]) { int x; for(i=0;i<5;i++){ x= array[i]; } return 0; } ``` it gives a warning as below, "parameter array could be declared const" ==> i already have declared the array const, i am programming in C++.

Original source