Answer the question
In order to leave comments, you need to log in
How to pass a pointer to an array into a function?
I have this C code:
static uint8_t uart_command_buf[42];
...
void uart_packet_damp(uint8_t uart_command_buf[]) {
for(int i = 0; i <= 41; i++)
{
printf("0x%02X ", uart_command_buf[i]);
}
}
...
uart_packet_dump(uart_command_buf);
static uint8_t uart_command_buf[42];
...
void uart_packet_dump(uint8_t *uart_command_buf[]) {
for(int i = 0; i <= 41; i++)
{
printf("0x%02X ", *uart_command_buf[i]);
}
}
...
uart_packet_dump(&uart_command_buf);
ud-rpl_root.c: In function 'char_in':
ud-rpl_root.c:151:26: warning: passing argument 1 of 'uart_packet_dump' from incompatible pointer type [-Wincompatible-pointer-types]
uart_packet_dump(&uart_command_buf);
^
ud-rpl_root.c:117:1: note: expected 'uint8_t ** {aka unsigned char **}' but argument is of type 'uint8_t (*)[42] {aka unsigned char (*)[42]}'
uart_packet_dump(uint8_t *uart_command_buf[]) {
^~~~~~~~~~~~~~~~
Answer the question
In order to leave comments, you need to log in
Should be void uart_packet_dump(uint8_t *uart_command_buf)
uint8_t *uart_command_buf[] similar to uint8_t **uart_command_buf
In C, you cannot pass an array by value.
This is where passing by pointer happens.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question