This commit is contained in:
gferg 2002-08-05 13:04:39 +00:00
parent 77117e3e7b
commit 1181968485
1 changed files with 46 additions and 4 deletions

View File

@ -10,7 +10,7 @@
<author><firstname>David A.</firstname> <surname>Wheeler</surname>
</author>
<address><email>dwheeler@dwheeler.com</email></address>
<pubdate>version 1.02, 13 July 2002</pubdate>
<pubdate>v1.04, 2 August 2002</pubdate>
<abstract>
<para>
This HOWTO for programmers
@ -1189,7 +1189,7 @@ For more information, see its documentation at
</sect2>
<sect2>
<sect2 id="removing-symbols">
<title>Removing symbols for space</title>
<para>
All the symbols included in generated files are useful for debugging,
@ -1217,7 +1217,7 @@ free, but this is a less flexible approach.
</para>
</sect2>
<sect2>
<sect2 id="small-executables">
<title>Extremely small executables</title>
<para>
You might find the paper
@ -1230,7 +1230,49 @@ ELF really works.
</para>
</sect2>
<sect2>
<sect2 id="cpp-vs-c">
<title>C++ vs. C</title>
<para>
It's worth noting that if you're writing a C++ program, and you're
calling a C library function, in your C++ code you'll need to define
the C function as extern "C".
Otherwise, the linker won't be able to locate the C function.
Internally, C++ compilers ``mangle'' the names of C++ functions
(e.g., for typing purposes), and they need to be told that a given
function should be called as a C function (and thus, not have its
name mangled).
</para>
<para>
If you're writing a program library that could be called from C or C++,
it's recommended that you include 'extern "C"' commands right in your
header files so that you do this automatically for your users.
When combined with the usual #ifndef at the top of a file to skip
re-executing header files, this means that a typical header file usable
by either C or C++ for some header file foobar.h would look like this:
<programlisting>
<![CDATA[
/* Explain here what foobar does */
#ifndef FOOBAR_H
#define FOOBAR_H
#ifdef __cplusplus
extern "C" {
#endif
... header code for foobar goes here ...
#ifdef __cplusplus
}
#endif
#endif
]]>
</programlisting>
</para>
</sect2>
<sect2 id="speeding-cpp-init">
<title>Speeding up C++ initialization</title>
<para>
The KDE developers have noticed that large GUI C++ applications can take