cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in struct on header file

MGarb.5
Associate II

Hi there!

I put this struct in the header file of my code, i´m using Cosmic C compiler and STM8S207 microcontroller:

typedef struct

{

bool a0:1; //flutuação

bool a1:1; //equalização

bool a2:1; //automático

bool a3:1; //fuga terra +

bool a4:1; //fuga terra -

bool a5:1; //sobretemperatura interna

bool a6:1; //sobretemperatura externa

bool a7:1; //disjuntor aberto

bool a8:1; //ca anormal

bool a9:1; //bateria baixa

bool a10:1;//bateria alta

bool a11:1;//consumidor baixo

bool a12:1;//consumidor alto

bool a13:1;//sobrecarga

bool a14:1;//bateria em descarga

bool a15:1;//desconexão bateria

}strAlarme;

strAlarme alarmes0;

But when i compile, i receive this message: #error cpstm8 declaracoes.h:36(1+9) redeclared typedef strAlarme

What am i doing wrong?

Sincerelly

Marcelo

1 ACCEPTED SOLUTION

Accepted Solutions
KnarfB
Principal III

The header file is probably included more than once.

  1. The typefdef must be protected by some #ifdef, see https://www.cprogramming.com/reference/preprocessor/ifndef.html
  2. Never define a variable (alarmes0) in a header file. Use an extern declaration instead.

hth

KnarfB

View solution in original post

2 REPLIES 2
KnarfB
Principal III

The header file is probably included more than once.

  1. The typefdef must be protected by some #ifdef, see https://www.cprogramming.com/reference/preprocessor/ifndef.html
  2. Never define a variable (alarmes0) in a header file. Use an extern declaration instead.

hth

KnarfB

MGarb.5
Associate II

Thanks KnarfB, you are right!!