Creating a Pointer in FORTRAN

Last reviewed: July 19, 1995
Article ID: Q51607
The information in this article applies to:
  • Microsoft FORTRAN for MS-DOS and OS/2, versions 5.0, 5.1

SUMMARY

The 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 INFORMATION

The 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 1

C 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 2

C 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
KBCategory: kbprg kbocde
KBSubcategory: FORTLngIss


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 19, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.