xlvi
An Overture to C Programmers
void extract_arkenstone();
struct MistyMountains {
int goblin_count;
};
Listing 14: The code remaining after the preprocessor processes Listing 13 in a C
environment
This is just a simple C header.
The code between the
#ifdef __cplusplus
statements is removed during preprocessing, so the
extern "C"
wrapper isn’t
visible. For the C++ compiler,
__cplusplus
is defined in
header.h
, so it sees the
contents of Listing 15.
extern "C" {
void extract_arkenstone();
struct MistyMountains {
int goblin_count;
};
}
Listing 15: The code remaining after the preprocessor processes Listing 13 in a C++
environment
Both
extract_arkenstone
and
MistyMountains
are now wrapped with
extern
"C"
, so the compiler knows to use C linkage. Now
your C source can call into
compiled C++ code, and your C++ source can call into compiled C code.
C++ Themes
This section takes you on a brief tour of some core themes that make C++
the premier system-programming language. Don’t worry too much about the
details. The point of the following subsections is to whet your appetite.
Dostları ilə paylaş: