Forum: Compiler & IDEs error: expected identifier or '(' before '=' token


von Werner D. (dorni)


Lesenswert?

Wer kann mir hier weiterhelfen?
bei folgend aufgeführtem Kode erhalte ich die Fehlermeldung:

../Entprellen-embedded.c:19: error: expected identifier or '(' before
'=' token

Code:
1
#include <avr/io.h>
2
#include <avr/interrupt.h>
3
#include <stdbool.h>
4
5
#define forever true 
6
#define OFF false 
7
#define ON true 
8
9
typedef int time_t;
10
typedef bool ioSwitch;
11
12
13
 //------------------------------------------------------------------------- 
14
 // Get Debounced Switch State
15
 bool IsSwitchStateChanged (void) 
16
 //------------------------------------------------------------------------- 
17
 { 
18
   static bool oldState = OFF; 
19
   ioSwitch = IO_SWITCH;      // grab Value from I/O 
20
 
21
   If (ioSwitch != oldState)  // if ioSwitch state has changed, do something 
22
      {  
23
    DebounceSwitch (); 
24
       oldState = ioSwitch;   // save state for next comparison 
25
       return true;           // ioSwitch state HAS changed
26
   }   
27
  return false;              // ioSwitch state HAS NOT changed
28
 }

von Stefan B. (stefan) Benutzerseite


Lesenswert?

Werner Dornstädter wrote:
> typedef bool ioSwitch;

Deklariert einen neuen Variablentyp namens ioSwitch

>    ioSwitch = IO_SWITCH;      // grab Value from I/O

Hier soll eine Variable definiert werden. Aber hier fehlt der 
Variablenname zwischen dem Variablentyp ioSwitch und dem =

Insgesamt würde deine Source laufen, wenn du das betreffende typedef 
weglässt und die Zuweisung so schreibst:

bool ioSwitch = IO_SWITCH;      // grab Value from I/O

von Gabriel W. (gagosoft)


Lesenswert?

hmm das wollte ich auch Antworten, dann war der Thread weg?!?

von Werner D. (dorni)


Lesenswert?

Danke Stefan für Deine Rückmeldung,
aber der Code will irgendwie nicht oder es besteht nun ein 
Mißverständnis.

Fehlermeldungen:

../Entprellen-embedded.c:17: error: 'IO_SWITCH' undeclared (first use in 
this function)
../Entprellen-embedded.c:17: error: (Each undeclared identifier is 
reported only once
../Entprellen-embedded.c:17: error: for each function it appears in.)
../Entprellen-embedded.c:19: warning: implicit declaration of function 
'If'
../Entprellen-embedded.c:20: error: expected ';' before '{' token

Code:
1
#include <avr/io.h>
2
#include <avr/interrupt.h>
3
#include <stdbool.h>
4
5
#define forever true 
6
#define OFF false 
7
#define ON true 
8
9
typedef int time_t;
10
11
//------------------------------------------------------------------------- 
12
// Get Debounced Switch State
13
bool IsSwitchStateChanged (void) 
14
//------------------------------------------------------------------------- 
15
{ 
16
   static bool oldState = OFF; 
17
   bool ioSwitch = IO_SWITCH;      // grab Value from I/O 
18
19
   If (ioSwitch != oldState)  // if ioSwitch state has changed, do something 
20
      {  
21
    DebounceSwitch (); 
22
       oldState = ioSwitch;   // save state for next comparison 
23
       return true;           // ioSwitch state HAS changed
24
   }   
25
  return false;              // ioSwitch state HAS NOT changed
26
}

von Hermann-Josef (Gast)


Lesenswert?

Tippfehler ?
1
  if (ioSwitch != oldState)  // if ioSwitch state has changed, do something

Also 'if' und nicht 'If', darauf deutet die Fehlermeldung hin.

Gruß
Hermann-Josef

von Werner D. (dorni)


Lesenswert?

Vielen Dank, Ihr habt mir weitergeholfen.
Und für den es interessiert, hier nun der aktuelle und bisher 
Fehlerfreie Code.
1
#include <avr/io.h>
2
#include <avr/interrupt.h>
3
#include <stdbool.h>
4
5
#define forever true 
6
#define OFF false 
7
#define ON true 
8
bool ioSwitch;
9
10
// for compilation
11
   bool IO_SWITCH = true;
12
   #define interrupt
13
14
//typedef int time_t;
15
16
//------------------------------------------------------------------------- 
17
void microcontrollerTask (void) 
18
//------------------------------------------------------------------------- 
19
{ 
20
  // do something 
21
  // this task takes (2 mS) to execute 
22
} 
23
24
25
//------------------------------------------------------------------------- 
26
void DebounceSwitch (void) 
27
//------------------------------------------------------------------------- 
28
{ 
29
  // do the Jack Ganssle software debounce 
30
} 
31
32
//------------------------------------------------------------------------- 
33
// Get Debounced Switch State
34
bool IsSwitchStateChanged (void) 
35
//------------------------------------------------------------------------- 
36
{ 
37
   static bool oldState = OFF; 
38
   ioSwitch = IO_SWITCH;      // grab Value from I/O 
39
40
   if (ioSwitch != oldState)  // if ioSwitch state has changed, do something 
41
      {  
42
    DebounceSwitch (); 
43
       oldState = ioSwitch;   // save state for next comparison 
44
       return true;           // ioSwitch state HAS changed
45
   }   
46
  return false;              // ioSwitch state HAS NOT changed
47
}

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.