Why is my struct syntax always causing errors when compiled?

This is my struct definition and declaration, I clearly wrote it according to C syntax, why do I keep getting errors?

typedef enum{
    Rx_Idle,
    Rx_Running,
    Rx_End,
    Rx_Overflow
}UartState_t;

typedef struct 
{
    u8 rx_buf[RX_BUFFER_SIZE];
    u8 rx_len;
    UartState_t state;

}Uart_t;

Uart_t Uart1 
{
    {0},
    0,
    Rx_Idle
};

This is an error message

error 1: Syntax error, declaration ignored at 'Uart1'
syntax error: token -> '}' ;column 7

Possibly the semicolon after UartState_t state;?

Cheers,
Norm.

What about this error below:

lib/uart/uart.h:26: syntax error: token -> '}' ; column 1
*** [.pio\build\STC89C52RC\src\main.rel] Error 1
lib\uart\/uart.h:26: syntax error: token -> '}' ; column 1
*** [.pio\build\STC89C52RC\lib1a3\uart\uart.rel] Error 1

This is code:

typedef struct 
{
    u8 rx_buf[RX_BUFFER_SIZE];
    u8 rx_len;
    UartState_t state
}Uart_t;

Uart_t Uart1 
{
    {0},
    0,
    Rx_Idle
};

I have found the error, it’s not about the ; error, Instead, should add = to the end of the struct, which is the code:

typedef struct
{
    u8 rx_buf[RX_BUFFER_SIZE];
    u8 rx_len;
    UartState_t state;
}Uart_t;

Uart_t Uart1 =
{
    {0},
    0,
    Rx_Idle
};
1 Like

Good spot. Better than mine! :wink:

Cheers,
Norm.

1 Like