Compaq Fortran 77 Release Notes for OpenVMS VAX Systems
*HyperReader
|
Example 2-2: Example of IARGCOUNT, IARGPTR and POINTER
C PROGRAM ARGLIST_TEST
INTEGER*4 X,Y,Z
X = 10
Y = 20
Z = 100
PRINT 800, %LOC(X), %LOC(Y), %LOC(Z)
800 FORMAT (' Argument addresses: ',3(1x, Z8.8))
CALL ARGLIST_SUB (X, Y, Z)
END
SUBROUTINE ARGLIST_SUB
! Declare pointer to argument list
POINTER (ARGLIST_P, ARGLIST_ENTRY)
INTEGER*4 ARGLIST_ENTRY
! Declare pointer to individual argument
POINTER (VALUE_P, VALUE)
INTEGER VALUE
! Get base address of argument list and skip over count
! Use SIZEOF to be somewhat architecture independent
!
ARGLIST_P = IARGPTR()+SIZEOF(ARGLIST_P)
! Display count of arguments and then, for each argument
! passed, display its value.
!
PRINT *,'Called with ',IARGCOUNT(), ' arguments'
DO I = 1, IARGCOUNT()
VALUE_P = ARGLIST_ENTRY ! Get address of argument
PRINT 900, I, VALUE_P, VALUE
900 FORMAT ( ' Argument ', I2, ' address = ', Z8.8,
1 ', contents = ', I5)
! Get address of next argument position
ARGLIST_P = ARGLIST_P + SIZEOF(ARGLIST_P)
END DO
RETURN
END