On many (most modern) architectures, trying to stuff a pointer into an
integer*4 will not work. But it is also not necessary. A simpler
version of your program is
subroutine MyRoutine()
implicit none
print *, "In routine"
end subroutine
program test
implicit none
procedure(),pointer :: ptr
external :: MyRoutine
ptr => MyRoutine
call ptr()
end
Procedure pointers were put into Fortran just so you would not have to
play the games below. Procedure pointers are a feature of the latest
standard, but I suspect IBM has them implemented. Customers ranked
procedure pointers pretty high on the implementation priority lists.
Cheers,
Bill
Drew Mccormack wrote:
> I have just been playing around with the 'external' keyword, trying
> to 'trick' fortran into storing a pointer to a subroutine for me.
> Alas, my XLF compiler tells me at run-time that I have issued an
> illegal instruction. Can anyone explain to me why the following
> doesn't work?
>
>
> subroutine MyRoutine()
> implicit none
> print *,'In routine'
> end subroutine
>
> subroutine Message(routine)
> implicit none
> external routine
> call routine()
> end subroutine
>
> subroutine saveOrMessageProcPointer(ptr, savePtr)
> implicit none
> integer*4 :: ptr
> logical :: savePtr
> integer*4, save :: savedPtr
> if ( savePtr) then
> savedPtr = ptr
> else
> call Message(savedPtr)
> endif
> end subroutine
>
> program Test
> implicit none
> external MyRoutine
> call saveOrMessageProcPointer(MyRoutine, .true.)
> call saveOrMessageProcPointer(MyRoutine, .false.)
> end program
>
>
> Regards,
> Drew
>
> ---------------------------------------------------------
> Drew McCormack
>
> www.maniacalextent.com
--
Bill Long [log in to unmask]
Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9142
Cray Inc., 1340 Mendota Heights Rd., Mendota Heights, MN, 55120
|