Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is this legal ?

Status
Not open for further replies.

narlytep

Programmer
Apr 18, 2006
10
GB
Hi there,
I've got a bit of code that I've been given to work on. It uses a structure constructor to initialise a derived type, but it uses a function within the constructor to set a pointer.

Is it legal to do this ? I'm getting different results on different compilers (Intel's compiler is OK with it, but PGI's fails with a very useless message).

Here's a simple test code showing the case:


MODULE Test
! Using a function to nullify or associate pointer
! in constructor of a simple derived type

implicit none

type deriv
real(kind=8), dimension:)), pointer :: ptr
end type deriv

real(kind=8),dimension:)),pointer::p

contains

subroutine foo()
integer(kind=4) :: i=1
type(deriv) , pointer :: derivptr

! Structure constructor fails with function inside

derivptr = deriv(pnull(p,i))

end subroutine foo

function pnull(pn,i)
! Returns pointer to pn or NULL, depending on value of i
integer(kind=4), intent(in) :: i
real(kind=8),dimension:)),pointer :: pn
real(kind=8),dimension:)),pointer :: pnull
nullify(pnull)
if (i > 0) pnull=>pn
end function pnull

END MODULE Test
 
It is just little things like the type declaration. My compiler throws it out if the type declaration is not followed by ::. Also both the subroutine and the function are missing return statements. Other than that it looks OK.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top