C 指针参数不匹配编译警告
C Pointer argument mismatch compilation warning
来自一个非常生疏的 C 想成为程序员的快速问题。我有以下场景
avr-gcc -Wall -Os -DF_CPU=8000000 -mmcu=atmega328p -c mirf.c -o mirf.o
mirf.c: In function ‘mirf_config’: mirf.c:76:20: warning: passing
argument 1 of ‘mirf_set_TADDR’ from incompatible pointer type
mirf_set_TADDR(&addr);
^ In file included from mirf.c:27:0: mirf.h:52:13: note: expected ‘uint8_t *’ but argument is of type ‘uint8_t (*)[5]’
extern void mirf_set_TADDR(uint8_t * adr);
void mirf_config()
// Sets the important registers in the MiRF module and powers the module
// in receiving mode
{
uint8 addr[5] = {0xA0,0xA1,0xA2,0xA3,0xA4};
mirf_set_TADDR(&addr); // HERE!!
// Set RF channel
mirf_config_register(RF_CH,mirf_CH);
// Set length of incoming payload
mirf_config_register(RX_PW_P0, mirf_PAYLOAD);
// Start receiver
PTX = 0; // Start in receiving mode
RX_POWERUP; // Power up in receiving mode
mirf_CE_hi; // Listening for pakets
}
void mirf_set_TADDR(uint8_t * adr)
// Sets the transmitting address
{
mirf_write_register(TX_ADDR, adr,5);
}
如何消除警告并将指针正确发送到 5 个字节?
谢谢!!
你想知道的就在这里:
mirf.h:52:13: note: expected ‘uint8_t ’ but argument is of type ‘int
()[5]’ extern void mirf_set_TADDR(uint8_t * adr);
mirf_set_TADDR
函数需要一个指向 uint8_t
的指针(即 uint8_t *
),但您向它传递的是数组的地址(即 uint8_t (*)[5]
).当传递给函数时,数组会衰减到第一个元素的地址,因此去掉寻址运算符:
mirf_set_TADDR(addr);
来自一个非常生疏的 C 想成为程序员的快速问题。我有以下场景
avr-gcc -Wall -Os -DF_CPU=8000000 -mmcu=atmega328p -c mirf.c -o mirf.o mirf.c: In function ‘mirf_config’: mirf.c:76:20: warning: passing argument 1 of ‘mirf_set_TADDR’ from incompatible pointer type mirf_set_TADDR(&addr); ^ In file included from mirf.c:27:0: mirf.h:52:13: note: expected ‘uint8_t *’ but argument is of type ‘uint8_t (*)[5]’ extern void mirf_set_TADDR(uint8_t * adr);
void mirf_config()
// Sets the important registers in the MiRF module and powers the module
// in receiving mode
{
uint8 addr[5] = {0xA0,0xA1,0xA2,0xA3,0xA4};
mirf_set_TADDR(&addr); // HERE!!
// Set RF channel
mirf_config_register(RF_CH,mirf_CH);
// Set length of incoming payload
mirf_config_register(RX_PW_P0, mirf_PAYLOAD);
// Start receiver
PTX = 0; // Start in receiving mode
RX_POWERUP; // Power up in receiving mode
mirf_CE_hi; // Listening for pakets
}
void mirf_set_TADDR(uint8_t * adr)
// Sets the transmitting address
{
mirf_write_register(TX_ADDR, adr,5);
}
如何消除警告并将指针正确发送到 5 个字节?
谢谢!!
你想知道的就在这里:
mirf.h:52:13: note: expected ‘uint8_t ’ but argument is of type ‘int ()[5]’ extern void mirf_set_TADDR(uint8_t * adr);
mirf_set_TADDR
函数需要一个指向 uint8_t
的指针(即 uint8_t *
),但您向它传递的是数组的地址(即 uint8_t (*)[5]
).当传递给函数时,数组会衰减到第一个元素的地址,因此去掉寻址运算符:
mirf_set_TADDR(addr);