Skip to main content
Visitor II
July 4, 2022
Solved

Problem in struct on header file

  • July 4, 2022
  • 2 replies
  • 2479 views

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

    This topic has been closed for replies.
    Best answer by KnarfB

    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

    2 replies

    KnarfBAnswer
    Super User
    July 4, 2022

    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.5Author
    Visitor II
    July 6, 2022

    Thanks KnarfB, you are right!!