cavratmelstudio

Facing difficulty in using typedef on a function.....getting error "redeclared as different kind of symbol"


UART_ATMEGA328.h

#define UART_ATMEGA328_H_

void USART_Init(unsigned long);             /* USART initialize function */
char USART_RxChar();                        /* Data receiving function */
void USART_TxChar(char);                    /* Data transmitting function */
void USART_SendString(char*);               /* Send string of USART data function */

#endif /* UART_ATMEGA328_H_ */ 

sim900.h

#define SIM900_H_

typedef void (*USART_Init)(unsigned long);
typedef void (*USART_SendString)(char*);
typedef void (*USART_TxChar)(char);

typedef struct
{
    USART_Init start;
    USART_SendString write;
    USART_TxChar tx;
    //Define anything else you need ..
}Sim900_Config_t;


void InitiateGSM(); //Check GSM
void SendSMS(char*); //Send SMS Function
void StoreSMS(); //Store SMS

#endif /* SIM900_H_ */

Error: 'USART_Init' redeclared as different kind of symbol/ 'USART_SendString' redeclared as different kind of symbol/ 'USART_TxChar' redeclared as different kind of symbol


Solution

  • You have a conflict between a function name and a type name. Nothing reasonable (ugly macros are not reasonable) can be done to resolve it.

    I suggest selecting a new name for the types. Like adding _cb or _f suffix (abbreviated from "callback" or "function").

    A minor tweak. Consider making types for the functions, not the function pointers. It makes type declaration more digestible, especially when the function pointer is passed as a parameter or returned. Moreover, it does not hide the pointer in typedef.

    typedef void config_init_f(unsigned long);
    typedef void config_send_string_f(char*);
    typedef void config_tx_char_f(char);
    
    typedef struct
    {
        config_init_f* start;
        config_send_string_f* write;
        config_tx_char* tx;
        //Define anything else you need ..
    }Sim900_Config_t;