Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28899 Discussions

How to rererence a pointer argument in a subroutine

jaeger0
Beginner
297 Views
I'm trying to make som dynamic objects, so I, want to return the pointer of a type.
If I make the Subroutine test, I get the Error "A dummy argument object cannot be a pointee. [PC]
"

If I make the function test2 I even get a catastrophic error "catastrophic error: **Internal compiler error: internal abort** Please report this error along with the circumstances in which it occurred in a Software Problem Report. Note: File and line given may not be explicit cause of this error."

subroutine test(pc)
use LST_DEF
implicit none
! input variables
! output variables
type(DUL_PRESENTATIONCONTEXT) pc

POINTER (p_addr, pc)

end subroutine

function test2() RESULT(pc)
use LST_DEF
implicit none
! input variables
! output variables
type(DUL_PRESENTATIONCONTEXT) pc

POINTER (p_addr, pc)

end function

0 Kudos
2 Replies
thomas_boehme
New Contributor II
297 Views
The pointers you are using are an extension to the FORTRAN standard often called Integer Pointers. The IVF manualexplicitly states that an integer pointer cannot point to a dummy argument (see section POINTER - Integer in the IVF manual). Therefore, what you are trying to do seems not to be allowed.
Using standardFORTRAN pointers howevershould work (see below).

regards,
Thomas

[plain]FUNCTION Test(arg) result(res)
TYPE (tArg), TARGET :: arg
TYPE (res),TARGET :: res
TYPE (tArg), POINTER :: p_arg
TYPE(res), POINTER :: p_res

p_arg => arg
p_res => res

END FUNCTION





[/plain]
0 Kudos
Paul_Curtis
Valued Contributor I
297 Views

This sort of thing is done all the time in Win32 programming, where the lParam argument frequently passes a pointer to some windows structure, depending on the message type:
[cpp]INTEGER FUNCTION MyProc (hwnd, msg, wParam, lParam) RESULT (res)
...
        IMPLICIT NONE
        INTEGER(HANDLE),  INTENT(IN)   :: hwnd
        INTEGER(UINT),    INTENT(IN)   :: msg
        INTEGER(fWPARAM), INTENT(IN)   :: wParam
        INTEGER(fLPARAM), INTENT(IN)   :: lParam
...
	TYPE(T_NMHDR)                  :: nmhdr
        POINTER(lParam, nmhdr)[/cpp]

I think the main idea here, where this code differs from your samples, is that the argument is declared as an integer, and then associated with the data type via the POINTER statement.
0 Kudos
Reply