|
This section covers the following topics:
Note:NOTE: As is the case with calling HP C from HP aC++, you must link your application using HP aC++.
The main() FunctionWhen
mixing C++ modules with modules in HP FORTRAN 90,
the overall control of the program must be written in C++. In
other words, the main() function must appear in
some C++ module and no other outer block should be present.
If you wish to have a main() function in a
module other than a C++ module, you can add a call to
_main() as the first non-declarative statement in the
module. However, if you use this method, your code is not
portable.
Function Naming ConventionsWhen
calling an HP FORTRAN 90 function from HP aC++ you
must keep in mind the differences between the way the languages
handle case sensitivity. HP FORTRAN 90 are not
case sensitive, while HP aC++ is case sensitive. Therefore, all
C++ global names accessed by FORTRAN 90 routines must
be lowercase. All FORTRAN 90 external names are
downshifted by default.
Using Reference Variables to Pass Arguments
There are two methods of passing arguments, by reference or by
value. Passing by reference means that the routine passes the
address of the argument rather than the value of the argument.
When calling HP FORTRAN 90 functions from HP aC++,
you need to ensure that the caller and called functions use the
same method of argument passing for each individual argument.
Furthermore, when calling external functions in HP
FORTRAN 90, you must know the calling convention for the order
of arguments.
It is not recommended that you pass structures or classes to
HP FORTRAN 90. For maximum compatibility and
portability, only simple data types should be passed to
routines. All HP aC++ parameters are passed by value, as in HP
C, except arrays and functions which are passed as pointers.
HP FORTRAN 90 passes all arguments by reference. This means
that all actual parameters in an HP aC++ call to a FORTRAN
routine must be pointers, or variables prefixed with the unary
address operator, &.
So, the simplest way to reconcile these differences in
argument-passing conventions is to use reference variables in
your C++ code. Declaring a parameter as a reference variable in
a prototype causes the compiler to pass the argument by
reference when the function is invoked.
Example:
int main( void )
{
// declare a reference variable
extern void pas_func( short & );
short x;
...
pas_func( x ); // pas_func should accept
... // its parameters by reference
}
Using extern "C" LinkageIf you want
to mix C++ modules with HP FORTRAN 90 modules, be
sure to use extern "C" linkage to declare any C++
functions that are called from a non-C++ module and to declare
the FORTRAN routines.
StringsHP aC++ strings are not the
same as HP FORTRAN 90 strings. In FORTRAN 90 the strings are not
null terminated. Also, strings are passed as string descriptors
in FORTRAN 90. This means that the address of the character item
is passed and a length by value follows.
Note: If you use the HP FORTRAN 90
+800 option, the length follows immediately after the
character pointer in the parameter list. If you do not use this
option, HP FORTRAN 90 passes character lengths by value at the
end of the parameter list. See the HP FORTRAN/9000
Programmer's Reference and the HP FORTRAN/9000
Programmer's Guide for information about the +800
option.
ArraysHP aC++ stores arrays in
row-major order, whereas HP FORTRAN 90 stores arrays in
column-major order. The lower bound for HP aC++ is 0. The
default lower bound for HP FORTRAN 90 is 1.
Files in HP FORTRAN
HP FORTRAN I/O routines require a logical unit number to access
a file, whereas HP aC++ accesses files using HP-UX I/O subroutines
and intrinsics and requires a stream pointer.
A FORTRAN logical unit cannot be passed to a C++ routine to
perform I/O on the associated file, nor can a C++ file pointer
be used by a FORTRAN routine. However, a file created by a program
written in either language can be used by a program of the other
language if the file is declared opened within the latter
program. HP-UX I/O (stream I/O) can also be used from
FORTRAN instead of FORTRAN I/O.
Refer to your system FORTRAN manual on
inter-language calls for details.
Linking HP FORTRAN 90 Routines
When calling HP FORTRAN 90 routines on the HP 9000 Series
700/800, you must include the appropriate run-time libraries by
adding certain arguments to the aCC command when linking your
program. These arguments depend on how you compiled your FORTRAN
90 routines.
32 bit PA-RISC 1.1 code:
-L/opt/fortran90/lib/ -lF90 -lisamstub
32 bit PA-RISC 2.0 code:
-L/opt/fortran90/lib/pa2.0/ -lF90 -lisamstub
64 bit PA-RISC 2.0 code:
-L/opt/fortran90/lib/pa20_64/ -lF90 -lisamstub
|