 |
» |
|
|
 |
Table 3-2 “HP C versus HP Fortran 90 Storage ” shows the differences
in storage allocation between HP C and HP Fortran 90. The notes
the table refers to are located after the table in the section called
"Notes on HP C and HP Fortran 90." Table 3-2 HP C versus HP Fortran 90 Storage HP C Type | HP C Description | HP Fortran 90 Type | HP Fortran 90 Description |
|---|
char, signed char, char enum | 1 byte, byte aligned |
| 1 byte, 1-byte aligned | unsigned char | 1 byte, byte aligned | CHARACTER*1 | 1 byte, 1-byte aligned | short, short enum | 2 bytes, 2-byte aligned | INTEGER*2 | 2 bytes, 2-byte aligned | unsigned short | 2 bytes, 2-byte aligned |
|
| int, int enum | 4 bytes, 4-byte aligned | INTEGER*4 or INTEGER | 4 bytes, 4-byte aligned | unsigned int | 4 bytes, 4-byte aligned |
|
| long, long enum | 4 bytes, 4-byte aligned (8 bytes in LP64) | INTEGER*4 or INTEGER | 4 bytes, 4-byte aligned | unsigned long | 4 bytes, 4-byte aligned (8 bytes in LP64) |
|
| float | 4 bytes, 4-byte aligned | REAL or REAL*4 | 4 bytes, 4-byte aligned | double | 8 bytes, 8-byte aligned | REAL*8 or DOUBLE PRECISION | 8 bytes, 8-byte aligned | long double | 16 bytes, 16-byte aligned | REAL*16 | 16 bytes, 16-byte aligned | (See Note 1) | 8 bytes, 4-byte aligned | COMPLEX or COMPLEX*8 | 8 bytes, 4-byte aligned | (See Note 2) | 16 bytes, 8-byte aligned | DOUBLE COMPLEX or COMPLEX*16 | 16 bytes, 8-byte aligned | enum | 4 bytes, 4-byte aligned | INTEGER*4 or INTEGER | 4 bytes, 4-byte aligned | pointer to type long
pointer to type |
| Not available |
| string (char *) |
| CHARACTER*n (See Note 3) |
| char array |
| CHARACTER*1 array (See Notes 4 &5) |
| (See Note 5) |
| Hollerith array |
| arrays | Size is number of elements times element size.
Aligned according to element type. | (See Note 4) | Size is number of elements times element size.
Aligned according to element type. | struct | (See Note 6) | STRUCTURE | Used to declare Fortran 90 record structures. | union | (See Note 6) | UNION | Used to declare Fortran 90 union types. | short (used for logical test) | 2 bytes, 2-byte aligned | LOGICAL*2 (See Note 7) | 2 bytes, 2-byte aligned | int (used for logical test) | 4 bytes, 4-byte aligned | LOGICAL*4 (See Note 7) | 4 bytes, 4-byte aligned | void | | Used when calling a SUBROUTINE |
| function |
| Used when calling a FUNCTION |
|
Notes
on HP C and HP Fortran 90 |  |
The following HP C structure is equivalent to the HP Fortran
90 type listed in the table: struct complex { float real_part; float imag_part; }; The following HP C structure is equivalent to the
HP Fortran 90 type listed in the table: struct double_complex { double real_part; double imag_part; }; HP Fortran 90 passes strings as parameters using
string descriptors corresponding to the following HP C declarations: char *char_string; /* points to string */ int len; /* length of string */ HP C stores arrays in row-major order, whereas HP
Fortran 90 stores arrays in column-major order. The lower bound
for HP C is always zero; for HP Fortran 90, the default lower bound
is 1. HP C terminates character strings with a null byte,
while HP Fortran 90 does not. The size is equal to the size of all members plus
any padding needed for the alignment. (See Chapter 2 for details
on alignment.) The alignment is that of the member with the strictest
alignment requirement. HP C and HP Fortran 90 do not share a common definition
of true or false. In HP Fortran 90, logical values are determined
by the low-order bit of the high-order byte. If this bit is 1, the
logical value is .TRUE., and if the bit is zero, the logical value is .FALSE.. HP C interprets nonzero value as true and
interprets zero as false.
Mixing
C and Fortran File I/O |  |
A Fortran 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 and opened within the latter program. C
accesses the file using I/O subroutines and intrinsics. This method
of file access can also be used from Fortran instead of Fortran
I/O. Be aware that HP Fortran 90 on HP 9000 workstations and servers using
HP-UX uses the unbuffered I/O system calls read and write (described in the HP-UX Reference manual)
for all terminal I/O, magnetic tape I/O, and direct access I/O.
It uses the system calls fread and fwrite for all other I/O. This can cause problems in
programs that mix C and Fortran I/O. In particular, C programs that
use stdio(3S) output procedures such as printf and fwrite and Fortran output statements must flush stdio buffers (by calling the libc function fflush) if they are in use before returning to Fortran
output or the I/O may be asynchronous (if the library is using write). Mixing Fortran direct, terminal, or tape READ statements with stdio fread input results in the Fortran READ commencing from
the beginning of the next block after the contents of the buffer,
not from the current position of the input cursor in the fread buffer. The same situation in reverse may occur
by mixing read with a Fortran sequential disc read. You can avoid
these problems by using only the read and write calls in the C program that the Fortran I/O library
uses. Passing
Parameters Between HP C and HP Fortran 90 |  |
All parameters in HP Fortran 90 are passed by reference. This
means that all arguments in an HP C call to an HP Fortran 90 routine
must be pointers. In addition, all parameters in an HP C routine
called from HP Fortran 90 must be pointers, unless the HP Fortran
90 code uses the $ALIAS directive to define the parameters as value parameters.
Refer to the example called "HP Fortran 90 Nested Structure" later
in this chapter. Passing string variables of any length must be done by: building
and passing a two-parameter descriptor (defined in Note 3 above),
initializing the string appropriately, and by passing two arguments.
The two arguments are the pointer to the characters
and the value of the length word.  |  |  |  |  | NOTE: Type of the length
argument in 32 bit mode should be int, and in 64 bit mode it should
be long". |  |  |  |  |
In 64 bit mode: char *s = "Big Mitt"; long len; . . . len = strlen(chars); pass_c_string(chars, len); . . . In 32 bit mode: char *chars = "Big Mitt"; int len; . . . len = strlen(chars); pass_c_string (chars, len); . . . Linking
HP Fortran 90 Routines on HP-UX |  |
When calling HP Fortran 90 routines on an HP-UX system, you
have to include the HP Fortran 90 run-time libraries by adding the
option: -lcl to the cc command line. For details on linking external libraries, see the -l option of the cc(1) and ld(1) commands in the HP-UX Reference manual.
|