User talk:Kr/Parameterized Headers
From Apache OpenOffice Wiki
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
- include "mycode.hxx"
- include <anyotherheader.hxx>
- Parameterize base header
"mycode.hxx"[cpp]
- define PARAMETER_FOR_PARA_HEADER 27
- include <paraheader.hxx>
void testfun(void *)
"mycode.cxx"[cpp]
- include <mycode.hxx>
/* Even if (in)directly including "paraheader.hxx" again,
it is parametrized correctly (which would not be true, if including it first). */
- include "paraheader.hxx"
- Parameterizeable header
"paraheader.hxx"[cpp]
- if PARAMETER_FOR_PARA_HEADER == 27
void testfun(int para = "dies");
- else
void testfun(int para = "dass");
- endif
- Inherit Header Parameters
"mycode.hxx"[cpp]
- include <paraheader.hxx>
"mycode.cxx"[cpp]
- include <mycode.hxx>
void aFun() { }