[sdiy] OT (but very synthy): C question

Olivier Gillet ol.gillet at gmail.com
Tue Mar 29 17:32:08 CEST 2011


> I use LFO_H_ because it's easy to remember. A declaration xxx_H_
> is only defined in the header file that contains it. That way any
> file that needs that function can include it. I.E.

This works until your UTILS_H_ (or every generic name) collides with
someone else's UTILS_H_ deep in a dependency. Hence the idea of adding
a path or project-specific prefix to each header guard.

> and then the big question is why are we processing
> midi and LFO in the MIDI header?

Tom has to answer this one!

> This should be at a higher level either the main.c
> or a sub-level that includes both MIDI.h and LFO.h.

I think every public function related to midi should be declared in
midi.h and implemented in midi.c ; and avoiding forward declarations
is not a good reason to change this. To me, headers only have a
declarative value, hence they should contain only what is necessary to
allow the declarations to be done. Another advantage of lightweight
headers - with as many forward declarations as possible - and as
little nested .h as possible - is the reduced number of dependencies.
This avoids the "contamination" of a change in the declaration of a
struct to all the source files that only pass around a
reference/pointer of this struct and which are not really bothered by
the change. This doesn't really matter on an embedded project, but on
projects with 100+ source files this helps a lot - so it's a good
habit to take.

Olivier



More information about the Synth-diy mailing list