[sdiy] OT (but very synthy): C question
ChristianH
chris at chrismusic.de
Tue Mar 29 16:17:30 CEST 2011
The .h files should have their own type declarations *first*, and then
#include other .h files.
Finally, you can have your function prototypes, using types from both .h
files.
Things can get a bit more ugly if you need have structs
cross-referencing each other. That's when forward declarations come in.
Chris
On Tue, 29 Mar 2011 14:41:37 +0100 Tom Wiltshire <tom at electricdruid.net>
wrote:
> I've been using the inclusion guards, but they don't solve the problem.
>
> For example, think what happens when LFO.h includes MIDI.h and vice versa.
>
> Let's assume LFO.h is loaded first. It isn't defined yet, so it gets #defined, and then we come to the includes, midi.h. That gets fed in, since it isn't defined yet either. It includes LFO.h, which is ignored since it is already defined. All fine so far.
> Until we get to halfway down midi.h, where there's a reference to an LFO structure which hasn't been set up, since we got to this point from the include statement way back at the beginning of LFO.h
>
> So I don't see how the inclusion guards actually help at all.
>
> I'm still trying to get the forward declarations to work instead, but somehow it keeps chucking syntax errors. I've set up a new project with the same layout and structures, but very stripped down code so that I've got a simple place to test things. Once I get it working there, I'll take my new understanding back t the actual project.
>
> T.
>
>
> On 29 Mar 2011, at 14:18, Tim Daugard wrote:
>
> >>> Use inclusion guards
> >>> In one file (MIDI.h)
> >>> #ifndef MIDI_H
> >>> #define MIDI_H
> >>> #ifndef LFO_H
> >>> #include "LFO.h"
> >>> #endif
> >>> ...
> >>> #endif
> >
> >> You don't need the inner inclusion guards, the outer per-file ones are
> >> sufficient.
> >
> > I use the outer ones as the standard process this file once.
> >
> > The inner ones (when used are to grab things that I know have to be
> > grabbed to make this file work.
> >
>
> _______________________________________________
> Synth-diy mailing list
> Synth-diy at dropmix.xs4all.nl
> http://dropmix.xs4all.nl/mailman/listinfo/synth-diy
More information about the Synth-diy
mailing list