%VAL and %REF (IBM extension)

To call subprograms written in languages other than Fortran (for example, user-written C programs, or AIX® operating system routines), the actual arguments may need to be passed by a method different from the default method used by XL Fortran. The default method passes the address of the actual argument and, if it is of type character, the length. (Use the -qnullterm compiler option to ensure that scalar character constant expressions are passed with terminating null strings. See -qnullterm option in the XL Fortran Compiler Reference for details.)

The default passing method can be changed by using the %VAL and %REF built-in functions in the argument list of a CALL statement or function reference, or with the dummy arguments in interface bodies. These built-in functions specify the way an actual argument is passed to the external subprogram.

%VAL and %REF built-in functions cannot be used in the argument lists of Fortran procedure references, nor can they be used with alternative return specifiers.

The argument list built-in functions are:
%VAL
This built-in function can be used with actual arguments that are CHARACTER(1), logical, integer, real, complex expressions, or sequence derived type. Objects of derived type cannot contain character structure components whose lengths are greater than 1 byte, or arrays.

%VAL cannot be used with actual arguments that are arrays, derived types with allocatable components, procedure names, or character expressions of length greater than 1 byte.

%REF
This built-in function causes the actual argument to be passed by reference; that is, only the address of the actual argument is passed. Unlike the default passing method, %REF does not pass the length of a character argument. If such a character argument is being passed to a C routine, the string must be terminated with a null character (for example, using the -qnullterm option) so that the C routine can determine the length of the string.

Examples

  EXTERNAL FUNC
  CALL RIGHT2(%REF(FUNC))       ! procedure name passed by reference
  REAL XVAR
  CALL RIGHT3(%VAL(XVAR))       ! real argument passed by value

  IVARB=6
  CALL TPROG(%VAL(IVARB))       ! integer argument passed by value

See VALUE (Fortran 2003) for a standard-conforming alternative to %VAL.