I have a fixed size array (which will be always of the same size) containing bytes. Here is the code:
static void foo(uint8_t *arr_ptr);
void main()
{
uint8_t arr[4];
foo(&arr);
}
static void foo(uint8_t *arr_ptr)
{
for(uint8_t i=0; i<4; i++)
{
arr_ptr[i]=1; // Set to one just to make it simpler
}
}
The idea is to have a fixed size array at main as a buffer, and modify its content every time foo is called. It works as it should, but it gives some warnings and info's that makes me think something is not correctly stated.
At
static void foo(uint8_t *arr_ptr);: INFO: expected 'uint8_t*{aka unsigned char }' but argument is of type 'uint8_t()[4]{aka unsigned char (*)[4]}'At
foo(&arr): WARNING: passing argument 1 of 'foo' from incompatible pointer type
Digging a bit at some other posts, I've seen that maybe a solution could be to declare it as (*arr)[4], which may have sense, but applying them makes the code work different. I'm pretty sure I'm making my mind a mess with this pointer declaration and argument passing, so I'd appreciate if someone can help me clarify these concepts.
foo(&arr);-->foo(arr);&arris a pointer to the array itself, it has the typeuint8_t (*)[4]. You want to pass a pointer to the first element, which is&arr[0], or plainarras that will decay to a pointer to the first element. That pointer will have the expected type ofuint8_t *.