User talk:Kr/Parameterized Headers

From Apache OpenOffice Wiki
Jump to: navigation, search

Some thoughts about C/C++ headers.

Kinds of C/C++ Headers

  • A header provides the interface to (parts) of zero or multiple libraries.
  • A header may include other headers.
  • A header may be parametrizable (parameters may be mandatory), a header is parametrizable, if it reacts on defines.
  • A header inherits parameters from included headers.
  • A header may be comprehensive.

Tips

Include headers in reverse order of Distance.

This ensures

  • that the compiler produces an error in case the header is not complete, and
  • that successive (parametrizable) headers are configured properly.

Parametrize successive headers in the header and according to the headers code.

Examples

Matching header first
"mycode.hxx" [cpp]

void testfun(void *); "mycode.cxx"[cpp] // include matching header first

  1. include "mycode.hxx"
  2. include <anyotherheader.hxx>

Parameterize base header
"mycode.hxx"[cpp]
  1. define PARAMETER_FOR_PARA_HEADER 27
  2. include <paraheader.hxx>

void testfun(void *) "mycode.cxx"[cpp]

  1. include <mycode.hxx>

/* Even if (in)directly including "paraheader.hxx" again,

  it is parametrized correctly (which would not be true, if including it first). */
  1. include "paraheader.hxx"

Parameterizeable header
"paraheader.hxx"[cpp]
  1. if PARAMETER_FOR_PARA_HEADER == 27
 void testfun(int para = "dies");
  1. else
 void testfun(int para = "dass");
  1. endif

Inherit Header Parameters
"mycode.hxx"[cpp]
  1. include <paraheader.hxx>

"mycode.cxx"[cpp]

  1. include <mycode.hxx>

void aFun() { }

Personal tools