HP 3000 Manuals

ALIAS Directive [ HP FORTRAN 77/iX Reference ] MPE/iX 5.0 Documentation


HP FORTRAN 77/iX Reference

ALIAS Directive 

The ALIAS directive specifies that a subroutine, function, entry, or
common block name has an external name different from its internal name
and, optionally, that a subroutine or function has a nonstandard calling
sequence or parameter passing mechanism.

Specifying the name of the language automatically generates the
appropriate type of parameter for that language.  Thus, specifying Pascal
causes all parameters, including character, to be passed by reference;
specifying C causes all noncharacter parameters less than or equal to 64
bits to be passed by value and all others by reference.  The ALIAS
directive applies to subroutines, entries, and functions used externally;
the directive does not apply to the program unit being defined.

The ALIAS directive can function in two modes:  local and global.

Syntax 

                                  [Pascal] [  {%VAL  }         ]
$ALIAS name [= {'external_name'}] [C     ] [( {%REF  } [,...] )]
            [  {"external_name"}] [COBOL ] [  {%DESCR}         ]

name                is a named common block name if it is enclosed in
                    slashes, or else a subroutine, function, or entry
                    name.

external_name       is a string that can include special characters.
                    When external_name is specified, the compiler changes
                    the external name of the subroutine or common block
                    to the specified string.  external_name must be
                    delimited by single quotation marks and is
                    downshifted by default, unless an UPPERCASE or
                    LITERAL_ALIAS directive specifies otherwise.

Default               None.

Location              A global ALIAS directive must appear before the
                      program head of the program unit (or before the
                      first statement of a default program, that is, one
                      with no PROGRAM statement).

                      A local ALIAS directive must appear within the
                      boundaries of a particular program unit; that is it
                      must appear after the program head of the program
                      unit (PROGRAM, SUBROUTINE, or FUNCTION statement),
                      if any, and before any DATA, statement function, or
                      executable statement.

Toggling/ Duration    A global ALIAS directive applies to all program
                      units subsequent to its appearance.

                      A local ALIAS directive applies only to the
                      particular program unit and is not defined for
                      later program units.

                      Attempts to redefine ALIAS names generate a warning
                      message.

Additional Information 


NOTE The compiler always changes external_name to lower case, no matter how it is entered. If you want to pass this parameter in mixed case, use the LITERAL_ALIAS directive; if you want to pass it in upper case, use the UPPERCASE directive.
The language option enables the compiler to correctly pass parameters to other languages. If you make no specification, the compiler assumes you are calling an HP FORTRAN 77 subprogram. If %VAL, %REF, or %DESCR appears in the ALIAS directive, it represents the parameter passing information for the given subroutine or function, which must be external. There are three parameter passing mechanisms: %VAL passing by value. %REF passing by reference (the default for noncharacter data). %DESCR passing by descriptor (the default for character data and for all procedures). Using alternative parameter passing information allows a FORTRAN program or subprogram to call a procedure or function written in another language, such as Pascal or C. This includes system intrinsic functions (which are described in the appropriate reference manual), as well as user-written routines. (Passing a datum by reference is equivalent in C to passing a pointer to that datum.) Using the language identification automatically takes care of character parameter passing for Pascal, and all parameter passing for Pascal if all are VAR parameters. Using the language identification automatically takes care of all parameter passing for C, provided C's standard conventions are followed. In C, all arrays, character variables greater than one byte, and other items that are greater than eight bytes are passed by reference. Other items (besides arrays and characters longer than one byte) that are less than or equal to eight bytes are passed by value in C. To pass a FORTRAN CHARACTER variable by reference instead of by descriptor (in other words, to pass a pointer to the variable itself instead of passing a descriptor), do the following: $ALIAS rout="extname" (%ref) . . . CHARACTER*10 name . . . CALL rout(name) Examples $ALIAS fun = '.CDBL' $ALIAS /blk/ = '$TIME' $ALIAS execle_2args = 'execle'(%REF,%REF,%REF,%VAL,%REF) $ALIAS copy_time = 'sprintf' C The ALIAS directive can also be used as another method of accessing some MPE/iX and library routines. However, because it is not a reliable method for accessing these, it is recommended that the interface routines be used instead whenever possible. An example of using the ALIAS directive is shown below: PROGRAM print_time * $ALIAS get_time = 'time' C (%ref) $ALIAS format_time = 'ctime' (%ref) $ALIAS copy_time = 'sprintf' C INTEGER format_time * CHARACTER*26 buf INTEGER char_ptr REAL*8 tmbuf * * get time since Jan 1, 1970 in numerical form * CALL get_time (tmbuf) * * convert numeric to ASCII string * char_ptr = format_time (tmbuf) * * now put C string into a FORTRAN string * CALL copy_time (buf, '%s'//char(0), char_ptr) * WRITE (6,*) buf END


MPE/iX 5.0 Documentation