Creating a Pointer in FORTRANLast reviewed: July 19, 1995Article ID: Q51607 |
The information in this article applies to:
SUMMARYThe two code examples below demonstrate one method to simulate a pointer in FORTRAN. The first example is for the MS-DOS operating system and the second is for the OS/2 operating system.
MORE INFORMATIONThe code example below demonstrates using a pointer in FORTRAN with MS-DOS. This program loads a far address into an INTEGER*4 variable and passes the variable to a subroutine. The program uses an INTERFACE TO SUBROUTINE statement to "lie" to FORTRAN about the data being passed. The INTERFACE statement indicates that the program passes an INTEGER*4 variable by value. Actually, the subroutine, to which the program refers using the ALIAS attribute, expects a far address to an array. The INTEGER*4 variable contains that address. The subroutine can refer to any value in the segment by specifying the correct index for the array. The SETPOINT2 subroutine changes the screen attribute byte to cause characters on the video display to blink.
Sample Code 1C Compile options needed: None
INTERFACE TO SUBROUTINE SETPOINT[ALIAS:'SETPOINT2'] (ABC)
INTEGER*4 ABC [VALUE]
END
SUBROUTINE SETPOINT2 (ABC)
INTEGER*2 ABC(*), N
DO 100, N = 1, 2000
ABC(N) = IOR(ABC(N), #8000)
100 CONTINUE
END
PROGRAM GRAPHTEST
INTEGER*4 PTR
PTR = #0B8000000
WRITE (*, '(Z9)') PTR
CALL SETPOINT (PTR)
END
The code example below demonstrates using a pointer in FORTRAN with
OS/2. This program retrieves a selector to the video buffer by calling
the VioGetPhysBuf() function. The application converts the selector to
a far pointer by shifting it 16 positions to the left.
The program uses an INTERFACE TO SUBROUTINE statement to "lie" to FORTRAN about the value it passes to the subroutine. The INTERFACE statement indicates that the program passes an INTEGER*4 by value. Actually, the subroutine, to which the program refers with an ALIAS attribute, expects a far address to an array. The INTEGER*4 variable contains that address. The subroutine can refer to any value in the segment by specifying the correct index for the array. The SETPOINT2 subroutine changes the screen attribute byte to cause characters on the video display to blink.
Sample Code 2C Compile options needed: None
INTERFACE TO FUNCTION VIOGETPHYSBUF (BUFFER, HANDLE)
STRUCTURE /BUFFSTRC/
INTEGER*4 ADDRESS
INTEGER*4 LENGTH
INTEGER*2 SELECTOR
END STRUCTURE
RECORD /BUFFSTRC/ BUFFER
INTEGER*2 HANDLE [VALUE]
INTEGER*2 VIOGETPHYSBUF
END
INTERFACE TO SUBROUTINE SETPOINT[ALIAS:'SETPOINT2'] (ABC)
INTEGER*4 ABC [VALUE]
END
SUBROUTINE SETPOINT2 (ABC)
INTEGER*2 ABC(*), N
DO 100, N = 1, 2000
ABC(N) = IOR(ABC(N), #8000)
100 CONTINUE
END
PROGRAM GRAPHTEST
STRUCTURE /BUFFSTRC/
INTEGER*4 ADDRESS
INTEGER*4 LENGTH
INTEGER*2 SELECTOR
END STRUCTURE
RECORD /BUFFSTRC/ BUFFER
INTEGER*2 ERROR, VIOGETPHYSBUF
INTEGER*4 PTR
BUFFER.ADDRESS = #0B8000
BUFFER.LENGTH = 4000
ERROR = VIOGETPHYSBUF (BUFFER, 0)
PTR = ISHA(BUFFER.SELECTOR, 16)
WRITE (*, '(Z10, I3)') PTR, ERROR
CALL SETPOINT (PTR)
END
|
Additional reference words: kbinf 5.00 5.10
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |