Difference between revisions of "User talk:Kr/Parameterized Headers"
From Apache OpenOffice Wiki
(Parameterized Headers) |
m (Some fixes.) |
||
Line 1: | Line 1: | ||
− | + | 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 provides the interface to (parts) of zero or multiple libraries. | ||
− | * A header may | + | * A header may include other headers. |
− | * A header may be | + | * 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. | ||
− | + | ==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 | + | * that successive (parametrizable) headers are configured properly. |
− | + | Parametrize successive headers in the header and according to the headers code. | |
− | + | ||
− | + | ||
+ | ==Examples== | ||
;Matching header first: | ;Matching header first: | ||
− | "mycode.hxx" | + | "mycode.hxx" <code>[cpp] |
− | + | void testfun(void *); | |
− | + | </code>"mycode.cxx"<code>[cpp] | |
− | + | // include matching header first | |
− | + | #include "mycode.hxx"<br> | |
− | + | #include <anyotherheader.hxx> | |
− | + | </code> | |
− | + | ||
− | + | ||
− | + | ||
;Parameterize base header: | ;Parameterize base header: | ||
− | "mycode.hxx" | + | "mycode.hxx"<code>[cpp] |
− | + | #define PARAMETER_FOR_PARA_HEADER 27 | |
− | + | #include <paraheader.hxx> | |
− | + | ||
− | + | void testfun(void *) | |
− | + | </code>"mycode.cxx"<code>[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" | |
− | + | </code> | |
;Parameterizeable header: | ;Parameterizeable header: | ||
− | + | "paraheader.hxx"<code>[cpp] | |
− | + | #if PARAMETER_FOR_PARA_HEADER == 27 | |
− | + | void testfun(int para = "dies"); | |
− | + | #else | |
− | + | void testfun(int para = "dass"); | |
− | + | #endif | |
− | + | </code> | |
− | + | ||
;Inherit Header Parameters: | ;Inherit Header Parameters: | ||
− | + | "mycode.hxx"<code>[cpp] | |
− | + | #include <paraheader.hxx> | |
− | + | </code>"mycode.cxx"<code>[cpp] | |
− | + | #include <mycode.hxx> | |
− | + | ||
− | + | ||
− | + | void aFun() { | |
− | + | } | |
+ | </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
- 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() { }