"enum" and "struct" in uController

Hi everyone,
I'm working with microcontroller (actually with XC32 compiler)programming in C,
and I using enum and struct as below.
1
2
3
4
5
6
7
8
9
10
11
12
typedef enum TimerMode
{   Timer_IDLE,
    Timer16Bits,
    Timer32Bits}TimerMode;
TimerMode CurrentMode = Timer_IDLE;

typedef struct PWM_Parameter{
    ...
    TimerMode PWM_Timer;
    ...
}PWM_Parameter;
PWM_Parameter PWM1;


It's compiled successfully just when In the declaration the new type's name is put twice, the same for PWM_Parameter.
However I saw in many source where declaring as below i enough.

1
2
3
4
5
6
7
8
9
typedef enum TimerMode 
{   ...
    };
TimerMode CurrentMode = Timer_IDLE;

typedef struct PWM_Parameter 
{   ...
    };
PWM_Parameter PWM1;


but I get this ERROR:

1
2
3
4
5
Main.c:38:5: warning: useless storage class specifier in empty declaration
Main.c:39:11: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'CurrentMode'
Main.c:48:5: error: expected specifier-qualifier-list before 'TimerMode'
Main.c:52:1: warning: useless storage class specifier in empty declaration
Main.c:53:15: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'PWM1'

Why the second way is wrong?
Maybe I'm wrong with my basis knowledge about C language
Topic archived. No new replies allowed.