我有以下 C 代码,对我来说看起来非常正确。然而,clang 编译器(事实上 gcc 或任何其他 C 编译器也是)不这么认为。
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 );
}
编译器给出以下警告和错误消息。知道这里有什么问题吗?
./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 )