2013-03-18 17 views
5

ottenuto il seguente struct dati:struct contenente un puntatore alla funzione con se stesso come un tipo di ritorno in C

typedef struct 
{ 
    lamp *lamp; 
    unsigned char a; 
    unsigned char b; 
    unsigned char c; 
    unsigned char d; 
    unsigned char e; 
    void (*func)(struct event *); 
} event; 

L'ultima riga all'interno della struct dovrebbe essere un puntatore a una funzione con tipo restituito vuoto con puntatore a un evento come argomento come ad esempio:

void function(event *evt); 

Anche se, io ottenere il seguente messaggio di avviso: "il suo scopo è solo che questa definizione o dichiarazione, che probabilmente non è ciò che si vuole". è giusto o sbagliato?

risposta

7

Le vostre esigenze struct deve essere definita in questo modo:

typedef struct event // <<< note the `event` tag here 
{ 
    lamp *lamp; 
    unsigned char a; 
    unsigned char b; 
    unsigned char c; 
    unsigned char d; 
    unsigned char e; 
    void (*func)(struct event *); 
} event;    // <<< you can still keep `event` as a typedef 
         //  which is equivalent to `struct event` 
+0

come @ Paolo ha detto typedef struct {MyStruct [...] } AliasForMyStruct; – Gilad

+0

grazie, risolto :) – user2182011

Problemi correlati