C/C++ Programmer's Guide (G06.25+)
C and C++ Extensions
HP C/C++ Programmer’s Guide for NonStop Systems—429301-008
2-5
Declarations
Examples for Native C/C++
For a complete programming example using export$ and import$ and producing a
DLL, see Examples on page 16-17.
import$ extern int I; /* OK--this is a data declaration*/
export$ extern int j = 1; /*OK--this is a data definition*/
export$ static int si; /*Error: static data */
import$ static int si = 0; /* Error: static data */
import$ extern int j; /* Warning: already specified as export$*/
import extern int i1 = 1; /* Error: this is a definition*/
export$ extern int i2; /* Error if i2 is not defined later*/
export$ int i3; /*Causes tentative def to be treated as a real def*/
import$ int i4; /*Causes tentative def to be treated as declaration*/
export$ static foo1 () {} /*Error: static function */
import$ static foo2 () {} /*Error:static function */
export$ extern foo3 () {} /* OK - extern function definition */
export$ extern foo4 (); /*Error: if foo4 not defined later*/
import$ extern foo5 (); /*OK - extern function declaration*/
import$ extern foo6 () {} /*Error: extern function definition */
Usage Guidelines for Export Attribute (Native C++ Only)
•
In C++, export$ and import$ can be specified for class definitions, as well as
for member functions and static data members. When given for a class definition,
these keywords specify that the entire class is either exported or imported,
including any Computer Generated class-specific data (CGD). When given for
specific members, then only those members are exported or imported. Within a
single compilation unit, a class is not allowed to both export and import members.
•
When you declare a class export$, all of its member functions, static data
members, and any CGDs are exported. Definitions for these member functions and
static data members must be provided. An error is issued for missing definitions.
Exported member functions are never inlined.
•
You can selectively mark member functions and static data members as export$
or import$ only if the entire class is marked as neither export$ nor import$.
The compiler generates an error if this rule is violated.
•
Selective member export/import is best used for providing a class interface that is
more restrictive, that is one in which fewer members are exposed to the class’s
clients.
•
If any member of a class is exported or imported, then all of its CGDs are also
exported or imported, respectively.