- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I will be looking at this later today.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I expect this to be fixed in Update 3 (May).
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page