Ich habe den folgenden C-Code, der sehr korrekt zu mir aussieht. Der "clam" -Compiler (eigentlich gcc oder irgendein anderer C-Compiler) denkt jedoch anders.Ich verstehe nicht, warum Compiler gibt mir Fehler mit diesem Code
typedef struct
{
struct timeval td_start;
struct timeval td_end;
} Timer;
void startTimer(struct Timer* ptimer)
{
gettimeofday(&(ptimer->td_start), NULL);
}
void stopTimer(struct Timer* ptimer)
{
gettimeofday(&(ptimer->td_end), NULL);
}
Der Compiler gibt folgende Waring & Fehlermeldungen. Irgendeine Idee, was hier falsch ist?
./timing.h:14:25: warning: declaration of 'struct Timer' will not be visible
outside of this function [-Wvisibility]
void startTimer(struct Timer* ptimer)
^
./timing.h:16:27: error: incomplete definition of type 'struct Timer'
gettimeofday(&(ptimer->td_start), NULL);
~~~~~~^
./timing.h:14:25: note: forward declaration of 'struct Timer'
void startTimer(struct Timer* ptimer)
^
./timing.h:19:24: warning: declaration of 'struct Timer' will not be visible
outside of this function [-Wvisibility]
void stopTimer(struct Timer* ptimer)
^
./timing.h:21:27: error: incomplete definition of type 'struct Timer'
gettimeofday(&(ptimer->td_end), NULL);
~~~~~~^
./timing.h:19:24: note: forward declaration of 'struct Timer'
void stopTimer(struct Timer* ptimer)
Eine bessere Lösung: Verwenden Sie nicht den Typedef! –
William: Aber Sie müssen struct mit einer Strukturvariablen in ANSI C rechts vorstellen! In C++ stimme ich struct ist nicht erforderlich. Nicht sicher über C99 obwohl. – pythonic