From: Nate Eldredge Newsgroups: comp.os.msdos.djgpp Subject: Re: Forward reference.... Date: 08 Nov 1999 10:39:07 -0800 Organization: InterWorld Communications Lines: 40 Message-ID: <83vh7c7rqs.fsf@mercury.st.hmc.edu> References: <8062tr$b6m$1 AT news DOT seed DOT net DOT tw> NNTP-Posting-Host: mercury.st.hmc.edu X-Trace: nntp1.interworld.net 942086410 28986 134.173.45.219 (8 Nov 1999 18:40:10 GMT) X-Complaints-To: usenet AT nntp1 DOT interworld DOT net NNTP-Posting-Date: 8 Nov 1999 18:40:10 GMT X-Newsreader: Gnus v5.7/Emacs 20.4 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com "cywu" writes: > Source code in xxx.h are as following: > > /* Forward reference of OsTimer. This is so it can be used in the > declaration > * of OsTimerNotify > */ > 93 typedef struct _OsTimer OsTimer; > typedef void (*OsTimerNotify)(OsTimer*); > typedef struct _OsTimer { > ListEntry node; > TimeT time; /* Time period of the timer in TimeT > units */ > OsTimerNotify func; /* Pointer to function called when timer > fires */ > TimeT startTime; > 100 } OsTimer; > but after compile, the error message is: > xxx.h:100: redefinition of 'OsTimer' > xxx.h:93: 'OsTimer' previously declare here Hmm... here's one way to do it. struct _OsTimer; /* This is the forward declaration */ typedef struct _OsTimer OsTimer; /* typedef it to the name we want */ typedef void (*OsTimerNotify)(OsTimer *); /* Now actually define struct _OsTimer; it's the one thing not yet defined. */ struct _OsTimer { ... OsTimerNotify func; ... }; -- Nate Eldredge neldredge AT hmc DOT edu