typedef struct-Fehler



  • Was ist falsch an diesem Code?

    [10]typedef struct {
    [11]	int command;
    [12]	int paramLength;
    [13]	char *params;
    [14]
    [15]	commadlistElement *previous;
    [16]} commadlistElement;
    

    Er sagt

    datatypes.h:15: error: syntax error before 'commadlistElement'
    datatypes.h:15: warning: no semicolon at end of struct or union
    datatypes.h:16: warning: type defaults to 'int' in declaration of 'commadlistEle
    ment'

    Hm :S



  • typedef struct commadlistElement {
    [11]    int command;
    [12]    int paramLength;
    [13]    char *params;
    [14]
    [15]    commadlistElement *previous;
    [16]} commadlistElement;
    

    🙂



  • Danke, aber Gleiche Fehlermeldungen



  • und so?

    typedef struct commadlistElement {
    [11]    int command;
    [12]    int paramLength;
    [13]    char *params;
    [14]
    [15]    struct commadlistElement *previous;
    [16]} commadlistElement;
    


  • So geht's! Vielen Dank. Aber noch ne Frage zur klärung: Sollte nicht die definition mit

    typedef struct {
        int command;
        int paramLength;
        char *params;
    
        commadlistElement *previous;
    } commadlistElement;
    

    Auch funktionieren, und dann so, das ich nicht immer struct davor schreiben muss wenn ich ein commadlistElement erzeugen will? Ich hab mit der funktionierenden Variante auch später noch

    commadlistElement *newCommand;
    

    im Text (ohne struct davor) und es geht!



  • Luke-2 schrieb:

    So geht's! Vielen Dank. Aber noch ne Frage zur klärung: Sollte nicht die definition mit

    typedef struct {
        int command;
        int paramLength;
        char *params;
    
        commadlistElement *previous;
    } commadlistElement;
    

    Auch funktionieren, und dann so, das ich nicht immer struct davor schreiben muss

    nein, weil das C und nicht C++ ist. Zu dem Zeitpunkt "commadlistElement *previous;" ist dem Compiler an sich noch nicht bekannt, dass commadlistElement ein typedef ist. Am besten macht man es so:

    typedef struct commadlistElement_t {
        int command;
        int paramLength;
        char *params;
    
        struct commadlistElement_t *previous;
    } commadlistElement;
    


  • supertux schrieb:

    Am besten macht man es so:

    typedef struct commadlistElement_t {
        int command;
        int paramLength;
        char *params;
    
        struct commadlistElement_t *previous;
    } commadlistElement;
    

    das hast du falsch herum gemacht 😉

    typedef struct commadlistElement {
        int command;
        int paramLength;
        char *params;
    
        struct commadlistElement *previous;
    } commadlistElement_t;
    


  • Gut, Danke Leute.



  • @vista: hab auch dran gedacht, aber es spielt keine Rolle, wo das _t angehängt wird.


Anmelden zum Antworten