HP Fortran Programmer Guide (766160-001, March 2014)
Note the following restrictions:
• Attempts to redefine $HP$ ALIAS names generate warning messages.
• The compiler always uses external-name exactly as it is entered. No case transformations
occur, and no underscore is appended. The +ppu and +uppercasecommand-line options
do not apply to external names specified by the $HP$ ALIAS directive.
Local and global usage
The $HP$ ALIAS directive can be used either locally or globally, as follows:
• The$HP$ ALIAS directive has local application only—that is, its effect is limited to a particular
program unit—if it appears within the boundaries of that program unit. To have local
application only, the directive must appear after any PROGRAM, SUBROUTINE, orFUNCTION
statement and before the first occurrence of name in the target program unit.
• The $HP$ ALIAS directive has global application—that is, it applies to all subsequent program
units—if it appears outside and before the boundaries of those program units to which it is to
apply.
Example 30 Examples
The $HP$ ALIAS directive is especially useful when calling a routine in a language that uses
different conventions than Fortran. The following examples illustrate how to use the $HP$ ALIAS
directive to resolve differences with:
• Case sensitivity
• Argument-passing conventions
• Strings
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 themalloc (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 elsizebecause 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)
Using HP Fortran directives 125