Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

procedural vars...

akagm
Beginner
859 Views
please, answer me...

may I use (how?) var, that holds any proc address?

smth like this:

WHAT_IS_THIS_TYPE PointerToSub
external someProc

PointerToSub = someProc
...
call PointerToSub(...)

thanks in advance...
0 Kudos
4 Replies
Jugoslav_Dujic
Valued Contributor II
859 Views
You have to use "Cray (Integer) pointers". To reference a procedure, use LOC(). To dereference it, use a cray pointer. In the meantime, you can use an integer to store it (or, better, integer(INT_PTR_KIND)):
!Referencing
external someProc
integer(int_ptr_kind()):: PointerToSub
PointerToSub = loc(someProc)
...
!Dereferencing
external aProc; pointer(paProc, aProc)
paProc = PointerToSub
call aProc(...) !actually calls someProc

Jugoslav
0 Kudos
akagm
Beginner
859 Views
thank You for answering...
but excuse my misunderstanding...

may You be more specific?

the task is:

- there is the global var pToSub (in some module for example)

- I "call" this pointer inside some sub Sub1
- and I want to change this pToSub in the different sub,
_outside_ Sub1 (Sub2 for ex.)

moreover, this var (and it's call) is resides in fortran DLL, but changing and the sub itseft are in the stand-alone independence (non-fortran) module...

may You write some code fragment?

thanks once more...
0 Kudos
Jugoslav_Dujic
Valued Contributor II
859 Views
Assuming you know how C pointers to subs work, the slight difference from Fortran Cray pointers are that the latter are dual (thus slightly less comprehensive). In the example above, paSub is, basically, of type INTEGER and can be used in integer operations. aSub is a procedure whose starting address is always equal to contents of paSub (i.e. = *paSub).

You can put the pointer-pair declaration as above in a module. Changing the contents of paSub causes the aSub to change address:
MODULE m
INTERFACE
  SUBROUTINE aSub()
  END SUBROUTINE
END INTERFACE
POINTER (paSub, aSub)
END MODULE m
!=======
PROGRAM Proggie
USE m
EXTERNAL foo, bar
paSub = LOC(foo)
CALL aSub()
paSub = LOC(bar)
CALL aSub()
END PROGRAM Proggie
!=======
SUBROUTINE foo()
WRITE(*,*) "Foo"
END SUBROUTINE foo
!=======
SUBROUTINE bar()
WRITE(*,*) "Bar"
END SUBROUTINE bar
Gives the output:
Foo
Bar
Of course, you can change value of paSub wherever you like.

Jugoslav
0 Kudos
akagm
Beginner
859 Views
it's now clear for me...

thanks!
0 Kudos
Reply