Schmidt: C: enum als Rückgabe und Übergabewert einer Funktion

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

  1. 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

    --
    Mein "Weblog" [RSS]
    Using XSLT to create JSON output (Saxon-B 9.0 for Java)
    »I don't believe you can call yourself a web developer until you've built an app that uses hyperlinks for deletion and have all your data deleted by a search bot.«
                -- Kommentar bei TDWTF