Tengo el siguiente código C, que me parece muy correcto. Sin embargo, el compilador de clang (de hecho, gcc o cualquier otro compilador de C también) piensa lo contrario.No entiendo por qué el compilador me está dando el error con este código
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);
}
El compilador da los siguientes mensajes de error Waring &. ¿Alguna idea de lo que está mal aquí?
./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)
Una mejor solución: ¡no use el typedef! –
William: ¡Pero tiene que ponerle un prefijo struct con una variable de estructura en ANSI C correcto! En C++ estoy de acuerdo con que struct no es necesario. No estoy seguro acerca de C99 sin embargo. – pythonic