2006-09-04 10:26:34 +02:00
|
|
|
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.
|
|
|
|
|
2009-10-11 20:25:29 +02:00
|
|
|
As an example, the following code fragment declares a function tt(xmalloc)
|
2006-09-04 10:26:34 +02:00
|
|
|
as a bf(C) function:
|
|
|
|
verb(
|
2009-10-12 13:02:43 +02:00
|
|
|
extern "C" void *xmalloc(int size);
|
2006-09-04 10:26:34 +02:00
|
|
|
)
|
|
|
|
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>
|
|
|
|
}
|
|
|
|
)
|
2009-10-11 20:25:29 +02:00
|
|
|
Although these two approaches may be used, they are actually seldom
|
2006-09-04 10:26:34 +02:00
|
|
|
encountered in bf(C++) sources. We will encounter a more frequently used
|
|
|
|
method to declare external bf(C) functions in the next section.
|