Print

Print



Can you please tell me under what circumstances DEALLOCATE  can cause
segmentation fault error? I was developing a program which simulate set
operation. Since the size of set will be relatively  small, I have decided
to use pointer with allocate instead of linked list. But, in the following
code, the statement 2 is causing segmentation fault error which I couldn't
understand why. If 2 is causing segmentation fault error, why not the
statement 1? 

    integer,dimension(:),pointer :: oldset, newset

    allocate(oldset(1))
    oldset(1) = 1
    do,...            <===== Go through lists of elem.       

        if we have to add elem to the newset,
            call putElement(newset,oldset,elem)
            print *, oldset                <====== 1
            deallocate(oldset,stat=error)  <====== 2
            if ( error /= 0 ) then
                print *,"Dealloc Error"
                stop
            end if
            oldset=>newset
            nullify(newset)
    end do

The newset is allocated inside putElement() routine.



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%