HP aC++/HP C A.06.25 Programmer's Guide

10 Mixing C++ with Other Languages
This chapter provides guidelines for linking HP aC++ modules with modules written
in HP C and HP FORTRAN 90 on HP 9000 Series 700/800 systems. It discusses the
following topics:
“Calling Other Languages” (page 247)
“Data Compatibility between C and C++” (page 247)
“HP aC++ Calling HP C” (page 248)
“HP C Calling HP aC++” (page 251)
“Calling HP FORTRAN 90 from HP aC++” (page 253)
Calling Other Languages
A module is a file that contains one or more variable or function declarations, one or
more function definitions, or similar items logically grouped together. Mixing modules
written in C++ with modules written in C is relatively straightforward since C++ is for
the most part a superset of C. Mixing C++ modules with modules in languages other
than C is more complicated.
When creating an executable file from a group of programs of mixed languages, one
of them being C++, you must be aware of the following:
In general, the overall control of the program must be written in C++. In other
words, the main function should appear in a C++ module and no other outer block
should be present.
You must pay attention to case sensitivity conventions for function names in the
different languages.
You must make sure that the data types in the different languages correspond. Do
not mismatch data types for parameters and return values.
Storage layouts for aggregates differ among languages.
You must use the extern "C" linkage specification to declare modules that are
not written in C++; this is true whether or not the module is written in C.
You must use the extern "C" linkage specification to declare modules that are
written in C++ and called from other languages.
Do not use extern "C" when you include standard C header files because these
header files already contain extern "C" directives.
NOTE: HP aC++ classes are not accessible to non-C++ routines.
Data Compatibility between C and C++
Many of the data types between C and C++ are identical as C++ is, for most part, a
superset of C. Both languages support char, short, int, long, float, and double
Calling Other Languages 247