Difference between revisions of "User talk:Kr/Parameterized Headers"

From Apache OpenOffice Wiki
Jump to: navigation, search
(Parameterized Headers)
 
m (Some fixes.)
 
Line 1: Line 1:
some thoughs about headers
+
Some thoughts about C/C++ headers.
 
+
HowTo
+
Include C / C++ Headers
+
  
 +
==Kinds of C/C++ Headers==
 
* A header provides the interface to (parts) of zero or multiple libraries.
 
* A header provides the interface to (parts) of zero or multiple libraries.
* A header may includes other headers.
+
* A header may include other headers.
* A header may be parameterizeable (parameters may be mandantory): Parameterizeable Headers A header is parameterizeable, if it reacts on defines.
+
* 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 inherits parameters from included headers.
 +
* A header may be comprehensive.
  
Include headers in reverse order of Distance.
+
==Tips==
 +
Include headers in reverse order of Distance.
  
 
This ensures
 
This ensures
* that the compiler produces an error in case the header is not complete,
+
* that the compiler produces an error in case the header is not complete, and
* that successve (parameterizeable) headers are configured properly
+
* that successive (parametrizable) headers are configured properly.
  
Parameterize successive headers in the header and according to the headers code.
+
Parametrize successive headers in the header and according to the headers code.
 
+
Examples
+
  
 +
==Examples==
 
;Matching header first:
 
;Matching header first:
  "mycode.hxx"
+
  "mycode.hxx" <code>[cpp]
<code>
+
void testfun(void *);
void testfun(void *);
+
</code>"mycode.cxx"<code>[cpp]
</code><br>
+
// include matching header first
"mycode.cxx"
+
#include "mycode.hxx"<br>
<code>
+
#include <anyotherheader.hxx>
// include matching header first
+
</code>
#include "mycode.hxx"<br>
+
#include <anyotherheader.hxx>
+
</code>
+
  
 
;Parameterize base header:
 
;Parameterize base header:
  "mycode.hxx"
+
  "mycode.hxx"<code>[cpp]
<code>
+
#define PARAMETER_FOR_PARA_HEADER 27
#define PARAMETER_FOR_PARA_HEADER 27
+
#include <paraheader.hxx>
#include <paraheader.hxx><br>
+
 
void testfun(void *)
+
void testfun(void *)
</code><br>
+
</code>"mycode.cxx"<code>[cpp]
"mycode.cxx"<br>
+
#include <mycode.hxx>
#include <mycode.hxx>
+
/* Even if (in)directly including "paraheader.hxx" again,  
// even if (in)directly including "paraheader.hxx" again, it is parameterized correctly (which would not be true, if including it first)
+
  it is parametrized correctly (which would not be true, if including it first). */
#include "paraheader.hxx"
+
#include "paraheader.hxx"
</code>
+
</code>
  
 
;Parameterizeable header:
 
;Parameterizeable header:
  <paraheader.hxx>
+
  "paraheader.hxx"<code>[cpp]
<code>
+
#if PARAMETER_FOR_PARA_HEADER == 27
#if PARAMETER_FOR_PARA_HEADER == 27
+
  void testfun(int para = "dies");
  void testfun(int para = "dies");
+
#else
#else
+
  void testfun(int para = "dass");
  void testfun(int para = "dass");
+
#endif
#endif
+
</code>
</code>
+
  
 
;Inherit Header Parameters:
 
;Inherit Header Parameters:
  <mycode.hxx>
+
  "mycode.hxx"<code>[cpp]
<code>
+
#include <paraheader.hxx>
#include <paraheader.hxx>
+
</code>"mycode.cxx"<code>[cpp]
 
+
#include <mycode.hxx>
  <mycode.cxx>
+
    #include <mycode.hxx>
+
  
    void aFun() {
+
void aFun() {
    }</code>
+
}
 +
</code>

Latest revision as of 09:00, 10 September 2007

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