1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Conflicting type error

Discussion in 'C' started by puneetnepsam, Jun 10, 2009.

  1. puneetnepsam

    puneetnepsam New Member

    Joined:
    Jun 10, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    i am writing a c code for microcontroller in the mplab compiler
    Code:
     
    typedef struct __attribute__ ((packed)) 
    {
     unsigned char ser_time_out_flag:1;
     unsigned char usb_time_out_flag:1;
     unsigned char sms_time_out_flag:1;
     unsigned char gprs_time_out_flag:1;
     unsigned char wr_power_log_flag:1;
     unsigned char sms_rx_flag:1;
    }S_GLOBAL_FLAG;
    typedef struct __attribute__ ((packed))       
    {
     unsigned char rxd_byte_ctr;
     unsigned char total_bytes;
     unsigned char cmd_type;
     unsigned char start_addr;
     unsigned char cal_checksum;
     unsigned char rxd_checksum;
     unsigned char ack_nack_byte;
     unsigned reception_start:1;
     unsigned pro_data:1;
    }S_SER_INFO; 
    typedef struct __attribute__ ((packed)) 
    {
       unsigned char  CmdBuf[RCV_BUFFER_SIZE];
       unsigned char  SerCmdTotalByte;
       unsigned       SerRcvDataInFlag:1;     // a global flag set when UART data Rcved
       unsigned       SerRcvCmdType   :2;     // CMD_GET or CMD_SET
       unsigned char  UsbCmdTotalByte;
       unsigned       UsbRcvDataInFlag:1;     // a global flag set when USB data Rcved
       unsigned       UsbRcvCmdType   :2;     // CMD_GET or CMD_SET   
    }S_CMD_BUF_INFO;
    
    following errors are coming:

    serial.h:60: error: conflicting types for 'S_GLOBAL_FLAG'
    serial.h:60: error: previous declaration of 'S_GLOBAL_FLAG' was here
    serial.h:73: error: conflicting types for 'S_SER_INFO'
    serial.h:73: error: previous declaration of 'S_SER_INFO' was here
    serial.h:86: error: conflicting types for 'S_CMD_BUF_INFO'
    serial.h:86: error: previous declaration of 'S_CMD_BUF_INFO' was here


    can anyone please tell me the problem and how to rectify it!!!
     
    Last edited by a moderator: Jun 11, 2009
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Use code blocks please.

    Are you including serial.h twice in the same code?
    For example if you include serial.h and foo.h, and foo.h itself includes serial.h, then the answer to this question is yes.
    A common solution to multiple includes is to add something along the following lines:
    Code:
    #ifndef _SERIAL_H_
    #define _SERIAL_H_
    
    // serial.h contents
    
    #endif
    
    Then when you include serial.h the first time, _SERIAL_H_ isn't defined, #ifndef evaluates TRUE and _SERIAL_H_ is defined. The second time serial.h is referenced the #ifndef evaluates FALSE and you don't get duplicate definitions.
     
  3. puneetnepsam

    puneetnepsam New Member

    Joined:
    Jun 10, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    thanks a lot buddy....
    my problem got solved....:charming:
     

Share This Page