Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

LOC of pointer argument

tried100times
Beginner
549 Views

Hi,

I have a problem taking the LOC of a pointer argument within a subroutine. It works fine on Mac and Linux with older versions of ifort (12). I am trying now on Windows with ifort 15 and it fails (loc returns the value of the variable instead of the address). Here is a minimal example:

program testloc
  implicit none
  real, pointer :: x
  integer(8) :: add1, add2

  allocate(x)
  x = 2
  add1 = loc(x)
  call get_add(x,add2)
  write(*,*) add1
  write(*,*) add2
  deallocate(x)
contains
  subroutine get_add(x,add)
      real, pointer, intent(in) :: x
      integer(8), intent(out) :: add
      add = loc(x)
  end subroutine
end program

On Mac/Linux it gives the output I expect (addresses always match).

On Windows with ifort 15.0.1 I get:

c:\code\MatlabAPI_lite>testloc
         4636400
               2

Is there a problem with my code? I'm not sure if it is a platform difference or a compiler version difference - I don't have access to any other versions to test. It has also always worked for me on Mac/Linux with gfortran.

Thanks for any help.

 

0 Kudos
7 Replies
tried100times
Beginner
549 Views

I should add I have tried both loc and %LOC. It does work on Windows if I remove the pointer attribute from the dummy argument of the subroutine - but in the real code I want to keep that there.

 

0 Kudos
andrew_4619
Honored Contributor II
549 Views
0 Kudos
tried100times
Beginner
549 Views

Thanks - I had come across that but in this case it didn't seem relevant. Here I need to use pointers because I am working with externally allocated memory (from Matlab).

I did get it working by using c_loc:

#define loc(x) transfer(c_loc(x),0_C_INTPTR_T)

did the trick. I'm not sure why I didn't do this when I originally wrote the code but I think I had trouble getting the transfer to work with c_ptr (it was a couple of years ago now).

Still I wonder why I had the problem only on Windows (but perhaps it is the version difference).

 

0 Kudos
FortranFan
Honored Contributor II
549 Views

FWIW, the code in the original post works fine with gfortran (4.9+).  I'm leaning toward a bug in Intel Fortran, hopefully one of Intel experts will take a look and investigate.

0 Kudos
Steven_L_Intel1
Employee
549 Views

I will be looking at this later today.

0 Kudos
Steven_L_Intel1
Employee
549 Views

Yep, looks like we broke this in 15.0. Earlier versions through 14.0.4 were ok. I have escalated this as issue DPD200366474 - thanks for bringing it to our attention.

0 Kudos
Steven_L_Intel1
Employee
549 Views

I expect this to be fixed in Update 3 (May).

0 Kudos
Reply