forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Weird error nullifying a pointer

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
ursuselasticus



Joined: 26 Mar 2005
Posts: 71

PostPosted: Fri Aug 19, 2022 7:13 pm    Post subject: Weird error nullifying a pointer Reply with quote

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

Code:

   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?
Back to top
View user's profile Send private message
ursuselasticus



Joined: 26 Mar 2005
Posts: 71

PostPosted: Fri Aug 19, 2022 11:03 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group