chamba
chamba

Reputation: 125

C Pointer argument mismatch compilation warning

quick question from a very rusty C wanna be programmer. I have the following scenario

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);
}

How do I get rid of the warning and properly send the pointer to the 5 bytes?

thanks!!

Upvotes: 0

Views: 449

Answers (1)

dbush
dbush

Reputation: 224437

What you need to know is right here:

mirf.h:52:13: note: expected ‘uint8_t ’ but argument is of type ‘int ()[5]’ extern void mirf_set_TADDR(uint8_t * adr);

The mirf_set_TADDR function is expecting a pointer to a uint8_t (i.e. a uint8_t *) but you're passing it the address of an array (i.e. a uint8_t (*)[5]). An array decays to the address of the first element when passed to a function, so get rid of the address-of operator:

mirf_set_TADDR(addr); 

Upvotes: 2

Related Questions