Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

ENTRY and variables sharing

V__Vadim
Beginner
84 Views

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
Steve_Lionel
Black Belt Retired Employee
84 Views

"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.

V__Vadim
Beginner
84 Views

Thanks for explanation.

Reply