Silverfrost Forums

Welcome to our forums

Weird error nullifying a pointer

19 Aug 2022 6:13 #29286

The below code gives me the error 'Reference to undefined variable ...' and I am at my wit's end tracking it down.

	subroutine EG_Plants()

    use EG_Data
	implicit none

   	integer EG_NewPlant
    integer EG_KillPlant

    integer iRslt

    type (Plants), pointer :: pPlantOld

    if (iiTSeed .eq. iiNTage)  then
      	iRslt = EG_NewPlant (50, 'Aussaat')
        return
    endif

    if (iiNPlants .le. 0) return

	pPlantOld => ppPlantHead
    print *,pPlantOld%iID             ! <--

	ppPlantCurrent => ppPlantHead

!	Lebenslauf der Pflanzen

    do
		print*, ppPlantCurrent%iID  ! <--

		pPlantOld => ppPlantCurrent
        print*, pPlantOld%iID                 ! <--       
		nullify (pPlantOld)

(Sorry, I did not find a way to have line numbers added)

The error occurs in the last line printed here, when the pointer pPlantOld is to be nullified. I added some print-lines to check the contents of the pointers marked with ! ←-. They work just fine and I receive three prints of the same ID-Number. Note: Variables with double leading characters are defined in module EG_Data.

What beats me is that I can have the contents of pPlantOld printed in one line - and in the very next line this pointer is undefined. And even if the status of this pointer may be undefined, this should not affect the nullify-operation, shoudn't it?

19 Aug 2022 10:03 #29287

Strange but I got it.

It was not the line that the compiler diagnostics pointed at (this was nullify(pPlantOld)) in the above listing, but the next one where there was a reference to an undefined variable!

Do not know how this came about, though.

Please login to reply.