Skip to content

Instantly share code, notes, and snippets.

@nyanpasu64
Created October 20, 2019 08:15
Show Gist options
  • Select an option

  • Save nyanpasu64/73ecebadb68bc8b28fa728c3f8f93d14 to your computer and use it in GitHub Desktop.

Select an option

Save nyanpasu64/73ecebadb68bc8b28fa728c3f8f93d14 to your computer and use it in GitHub Desktop.
Rules for avoiding circular header inclusion

Rules for avoiding circular header inclusion

C++ headers malfunction when there is an include cycle. I have designed some rules to prevent inclusion cycles (ensure topological sortability).

Abstract files (in order from common to derived). Each file can include all files listed above.

  • ../*_common.h
  • ./general_common.h
    • External libraries: none
  • ./specific_common.h
    • External libraries: specific -related libraries
  • ./specific/nested_common.h, if used
  • ./specific/nested.h
  • ./specific.h (public interface of . folder)
  • ./general.h, if used
  • ../app.cpp will interface mostly with ./specific.h (a public interface). I should try C++ modules.

Concrete files in this folder (in order from common to derived). Each file can include all files listed above.

  • audio_common.h (general audio types and functions, like Amplitude = s16)
  • output.h
    • Depends on output-related libraries (portaudio).
  • Application code depends on output.h.

and

  • audio_common.h
  • synth_common.h
    • Depends on synth-related libraries (blip_buf).
  • synth/Nes2A03Synth.h
    • class audio::synth::Nes2A03Synth
  • synth.h
  • Application code depends on synth.h.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment