cppannotations/yo/intro/cfunc.yo
Frank B. Brokken 56c3880916 WIP on chapter First
git-svn-id: https://cppannotations.svn.sourceforge.net/svnroot/cppannotations/trunk@252 f6dd340e-d3f9-0310-b409-bdd246841980
2009-10-12 11:02:43 +00:00

31 lines
1.1 KiB
Text

Normal bf(C) functions, e.g., which are compiled and collected in a run-time
library, can also be used in bf(C++) programs. Such functions, however, must be
declared as bf(C) functions.
As an example, the following code fragment declares a function tt(xmalloc)
as a bf(C) function:
verb(
extern "C" void *xmalloc(int size);
)
This declaration is analogous to a declaration in bf(C), except that the
prototype is prefixed with ti(extern "C").
A slightly different way to declare bf(C) functions is the following:
verb(
extern "C"
{
// C-declarations go in here
}
)
It is also possible to place preprocessor directives at the location of
the declarations. E.g., a bf(C) header file tt(myheader.h) which declares
bf(C) functions can be included in a bf(C++) source file as follows:
verb(
extern "C"
{
#include <myheader.h>
}
)
Although these two approaches may be used, they are actually seldom
encountered in bf(C++) sources. We will encounter a more frequently used
method to declare external bf(C) functions in the next section.