के साथ त्रुटि दे रहा है मेरे पास निम्न सी कोड है, जो मेरे लिए बहुत सही दिखता है। हालांकि, क्लैंग कंपाइलर (वास्तव में जीसीसी या कोई अन्य सी संकलक) अन्यथा सोचता है।मुझे समझ में नहीं आता क्यों संकलक मुझे इस कोड
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);
}
कंपाइलर निम्नलिखित waring & त्रुटि संदेश देता है। कोई विचार क्या गलत है?
./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)
एक बेहतर समाधान: टाइपपीफ का उपयोग न करें! –
विलियम: लेकिन आपको एएनएसआई सी में संरचना संरचना के साथ संरचना को उपसर्ग करना होगा! सी ++ में मैं सहमत हूं कि संरचना की आवश्यकता नहीं है। हालांकि सी 99 के बारे में निश्चित नहीं है। – pythonic