C: enum als Rückgabe und Übergabewert einer Funktion
Schmidt
- programmiertechnik
Hallo
ich versuche mit C eine Funktion zu basteln welche einen enum-Wert als Rückgabewert hat und als Übergabeparameter einen enum-wert übergeben bekommt.
Folgendes müsste meinem Verständniss nach funktionieren, tut es aber natürlich nicht.
Hat jemand eine Idee?
enum dspl_status { GET=0, ON, OFF, HINT }
dspl_status dspl(dspl_status stat){ //error: expected '=', ',', ';', 'asm' or '__attribute__' before 'dspl'
static dspl_status current_status = OFF; // Speichert den Aktuellen status der Anzeige. Anfangsert=OFF
return current_status;
}
Danke
Hallo,
Hat jemand eine Idee?
enum dspl_status { GET=0, ON, OFF, HINT }
dspl_status dspl(dspl_status stat){ //error: expected '=', ',', ';', 'asm' or 'attribute' before 'dspl'
static dspl_status current_status = OFF; // Speichert den Aktuellen status der Anzeige. Anfangsert=OFF
return current_status;
}
In C ist enum nicht automatisch auch ein Typ. Außerdem hast Du das ; hinter der } vergessen. Korrekt:
Variante 1:
~~~c
typedef enum { GET=0, ON, OFF, HINT } dspl_status;
dspl_status dspl(dspl_status stat){
static dspl_status current_status = OFF; // Speichert den Aktuellen status der Anzeige. Anfangsert=OFF
return current_status;
}
Variante 2:
enum dspl_status { GET=0, ON, OFF, HINT };
enum dspl_status dspl(enum dspl_status stat){
static enum dspl_status current_status = OFF; // Speichert den Aktuellen status der Anzeige. Anfangsert=OFF
return current_status;
}
Viele Grüße,
Christian