HP Fortran Programmer's Guide (B3908-90031; September 2011)

Using Fortran directives
Using HP Fortran directives
Chapter 9 211
Case sensitivity
Names in HP Fortran are not case sensitive; that is, the compiler converts all names to lowercase. This
means that if you reference a routine in a language that is case sensitive and the routine name contains
uppercase letters, a call to that routine in HP Fortran will result in an unresolved reference—unless you use
the $HP$ ALIAS directive to redefine the name in all lowercase letters, as in the following example:
!$HP$ ALIAS printnames = 'PrintNames'
Argument-passing conventions
By default, HP Fortran assumes that all parameters in a subroutine or function call are passed by reference;
that is, the call passes the addresses of the parameters, not their values. On the other hand, C code assumes
that parameters are passed by value; that is, the current value of the actual parameter is passed to the called
routine. Without the $HP$ ALIAS directive, it would be difficult to call a C routine from a Fortran
program.
For example, suppose you want to call the system routine calloc (see the malloc(3C) man page) to obtain
dynamic memory. The man page describes the calling sequence as:
char *calloc(unsigned nelem, unsigned elsize);
It would be difficult, using standard Fortran constructs, to provide actual parameters corresponding to
nelem and elsize because HP Fortran always passes addresses. The $HP$ ALIAS directive can solve
this problem by directing the compiler to generate call-by-value actual parameters:
!$HP$ ALIAS calloc(%VAL, %VAL)
Strings
Programs written in C expect strings to be terminated with the null character ('\0'). But HP Fortran
programs pass a hidden length parameter to indicate the end of a string argument. Thus, if you want to pass
a string from HP Fortran to a C language function, you must explicitly append the null to the string and
suppress the hidden length parameter. The $HP$ ALIAS directive enables you to pass the string from
Fortran to C. For example, consider the following routine:
Example 9-1 pr_str.c
void c_rout(char *s)
{
printf(“%s\n”, s);
}
The ALIAS directive in the following program enables the string to be passed to c_rout:
Example 9-2 pass_str.f90
PROGRAM main
!$HP$ ALIAS c_rout(%REF)
CHARACTER(LEN=10) name
name = 'Charlie'