Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
1 View

ENTRY and variables sharing

I know that ENTRY is obsolete but in my case it is the fastest way to accommodate old code to my purpose.
I expected that I can share variables between all ENTRYs. But I find strange difference.

Example:

      program test
      integer :: i
      i=10
      WRITE(*,*) 'I=',i
      call atest()
      call a1(i)
      call a2()
      end program

      subroutine atest()
        INTEGER  :: ic
        return

        entry a1(i)
          ic=i
          WRITE(*,*) 'entry 1'
          WRITE(*,*) 'ic=',ic
        return

        entry a2()
          WRITE(*,*) 'entry 2'
          WRITE(*,*) 'ic=',ic
      end subroutine

Default: 

> ifort test.f -o test
> ./test
I=          10
entry 1
ic=          10
entry 2
ic=           0

Debug:

> ifort -g test.f -o test
> ./test
I=          10
entry 1
ic=          10
entry 2
ic=          10

So, by default my common variable 'ic' is invisible to other entries, but not in debug mode.
Which one is correct ? I expected that debug mode is more correct.

Thanks.
(ifort (IFORT) 19.1.0.166 20191121)

0 Kudos
2 Replies
Highlighted
Black Belt
1 View

"ic" is not a "common

"ic" is not a "common variable - it is a local and is undefined when coming in through a2. You'll need to add the SAVE attribute to ic if you want this to work.

The debugger has limited information about variables and, especially in cases such as this, may get it wrong.

--
Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos
Highlighted
Beginner
1 View

Thanks for explanation.

Thanks for explanation.

0 Kudos