<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Bugreport: Function pointers and Fortran 2003 C interoperabilit in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Bugreport-Function-pointers-and-Fortran-2003-C-interoperability/m-p/750938#M7388</link>
    <description>I believe that this problem is fixed in Update 4.</description>
    <pubDate>Fri, 27 May 2011 22:03:58 GMT</pubDate>
    <dc:creator>Steven_L_Intel1</dc:creator>
    <dc:date>2011-05-27T22:03:58Z</dc:date>
    <item>
      <title>Bugreport: Function pointers and Fortran 2003 C interoperability</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Bugreport-Function-pointers-and-Fortran-2003-C-interoperability/m-p/750932#M7382</link>
      <description>The following code works as expected with gfortran, but fails with ifort-11.1.073 (64 Bit Linux)&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;[bash]icc-11.1.073 -O0 -ggdb -c test2.c -o test2.o
ifort-11.1.073 -nofor-main -O0 -ggdb test2f.f90 test2.o -o test2
./test2
Expecting 16: i = -7400[/bash]&lt;/PRE&gt; &lt;BR /&gt;&lt;BR /&gt;Sources are below&lt;BR /&gt;&lt;BR /&gt;test2.c&lt;BR /&gt;&lt;PRE&gt;[cpp]#include &lt;STDIO.H&gt;
#include &lt;SYS&gt;

void funcptr(void(*fptr) (int32_t));  

void test2(int32_t i) {
  printf("Expecting 16: i = %d\n", i);
}

int main(){  
  funcptr(test2);  
  return 1;  
} [/cpp]&lt;/SYS&gt;&lt;/STDIO.H&gt;&lt;/PRE&gt; &lt;BR /&gt;&lt;BR /&gt;test2f.f90&lt;BR /&gt;&lt;PRE&gt;[fortran]subroutine funcptr(c_test2) bind(c)  
  use, intrinsic :: iso_c_binding  
  interface
     subroutine test2(intval) bind(c)
       use iso_c_binding
       integer(c_int32_t), value :: intval
     end subroutine test2
  end interface
 
  type(c_funptr), value :: c_test2
  procedure(test2), pointer :: f_test2
  integer(c_int32_t) :: localint
 
  call c_f_procpointer(c_test2, f_test2)
  localint = 16
   
  call f_test2(localint)
  return
end subroutine funcptr[/fortran]&lt;/PRE&gt; &lt;BR /&gt;</description>
      <pubDate>Wed, 24 Nov 2010 21:18:53 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Bugreport-Function-pointers-and-Fortran-2003-C-interoperability/m-p/750932#M7382</guid>
      <dc:creator>adrianinteldev</dc:creator>
      <dc:date>2010-11-24T21:18:53Z</dc:date>
    </item>
    <item>
      <title>Bugreport: Function pointers and Fortran 2003 C interoperabilit</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Bugreport-Function-pointers-and-Fortran-2003-C-interoperability/m-p/750933#M7383</link>
      <description>I will admit I'm not a C expert, but isn't your C code just passing the address of test2 rather than a pointer containing the address of test2? The latter is what your Fortran code is expecting. When I try this on Windows, at least (that's what I have easier access to), that's what MSVC does. If I replace your Fortran code with this, it works:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;[fortran]subroutine funcptr(c_test2) bind(c)  
  use, intrinsic :: iso_c_binding  
  interface
     subroutine c_test2(intval) bind(c)
       use iso_c_binding
       integer(4), value :: intval
     end subroutine c_test2
  end interface
 
  integer(4) :: localint
 
  localint = 16
   
  call c_test2(localint)
  return
end subroutine funcptr[/fortran]&lt;/PRE&gt; &lt;BR /&gt;(I had to replace the c_int32_t with 4 on Windows).</description>
      <pubDate>Wed, 24 Nov 2010 22:09:29 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Bugreport-Function-pointers-and-Fortran-2003-C-interoperability/m-p/750933#M7383</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2010-11-24T22:09:29Z</dc:date>
    </item>
    <item>
      <title>Bugreport: Function pointers and Fortran 2003 C interoperabilit</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Bugreport-Function-pointers-and-Fortran-2003-C-interoperability/m-p/750934#M7384</link>
      <description>Thanks for the quick reply!&lt;BR /&gt;&lt;BR /&gt;No, I think this doesn't go far enough. In my understanding both test2 and &amp;amp;test2 are valid options to get the address of the function (strange, I know, but see for example &lt;A href="http://www.cprogramming.com/tutorial/function-pointers.html)" target="_blank"&gt;http://www.cprogramming.com/tutorial/function-pointers.html)&lt;/A&gt;. As you can see in the pasted output, the function is actually being called, only the arguments are scrambled.&lt;BR /&gt;&lt;BR /&gt;Replacing c_int32_t with 4 seems not make a difference on my machine.&lt;BR /&gt;&lt;BR /&gt;Could you try to run the test on 64-bit Linux, too? It seems to me like an ABI issue.</description>
      <pubDate>Wed, 24 Nov 2010 22:21:41 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Bugreport-Function-pointers-and-Fortran-2003-C-interoperability/m-p/750934#M7384</guid>
      <dc:creator>adrianinteldev</dc:creator>
      <dc:date>2010-11-24T22:21:41Z</dc:date>
    </item>
    <item>
      <title>Bugreport: Function pointers and Fortran 2003 C interoperabilit</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Bugreport-Function-pointers-and-Fortran-2003-C-interoperability/m-p/750935#M7385</link>
      <description>From the assembler output I think I can see what happens:&lt;BR /&gt;&lt;BR /&gt;(gdb) disassemble&lt;BR /&gt;Dump of assembler code for function funcptr:&lt;BR /&gt;0x0000000000400598 &lt;FUNCPTR&gt;: push %rbp&lt;BR /&gt;0x0000000000400599 &lt;FUNCPTR&gt;: mov %rsp,%rbp&lt;BR /&gt;0x000000000040059c &lt;FUNCPTR&gt;: sub $0x20,%rsp&lt;BR /&gt;0x00000000004005a0 &lt;FUNCPTR&gt;: mov %rdi,-0x20(%rbp)&lt;BR /&gt;0x00000000004005a4 &lt;FUNCPTR&gt;: lea -0x20(%rbp),%rax&lt;BR /&gt;0x00000000004005a8 &lt;FUNCPTR&gt;: mov $0x600f90,%edx&lt;BR /&gt;0x00000000004005ad &lt;FUNCPTR&gt;: mov %rax,%rdi&lt;BR /&gt;0x00000000004005b0 &lt;FUNCPTR&gt;: mov %rdx,%rsi&lt;BR /&gt;0x00000000004005b3 &lt;FUNCPTR&gt;: xor %eax,%eax&lt;BR /&gt;0x00000000004005b5 &lt;FUNCPTR&gt;: callq 0x400890 &lt;ISO_C_BINDING_MP_C_F_PROCPOINTER_&gt;&lt;BR /&gt;0x00000000004005ba &lt;FUNCPTR&gt;: movl $0x10,-0x8(%rbp)&lt;BR /&gt;0x00000000004005c1 &lt;FUNCPTR&gt;: mov 0x2009c8(%rip),%rax # 0x600f90 &lt;FUNCPTR&gt;&lt;BR /&gt;0x00000000004005c8 &lt;FUNCPTR&gt;: lea -0x8(%rbp),%rdx&lt;BR /&gt;0x00000000004005cc &lt;FUNCPTR&gt;: mov %rdx,%rdi&lt;BR /&gt;0x00000000004005cf &lt;FUNCPTR&gt;: mov %rax,-0x10(%rbp)&lt;BR /&gt;0x00000000004005d3 &lt;FUNCPTR&gt;: xor %eax,%eax&lt;BR /&gt;0x00000000004005d5 &lt;FUNCPTR&gt;: mov -0x10(%rbp),%rdx&lt;BR /&gt;0x00000000004005d9 &lt;FUNCPTR&gt;: callq *%rdx&lt;BR /&gt;0x00000000004005db &lt;FUNCPTR&gt;: movq $0x0,-0x18(%rbp)&lt;BR /&gt;0x00000000004005e3 &lt;FUNCPTR&gt;: leaveq &lt;BR /&gt;0x00000000004005e4 &lt;FUNCPTR&gt;: retq &lt;BR /&gt;0x00000000004005e5 &lt;FUNCPTR&gt;: nop &lt;BR /&gt;End of assembler dump.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The problem is that instead of the &lt;I&gt;value&lt;/I&gt; (as specified by the interface), the &lt;I&gt;address&lt;/I&gt; of the localint is written into register rdi, which is where the C function expects parameter 0.&lt;/FUNCPTR&gt;&lt;/FUNCPTR&gt;&lt;/FUNCPTR&gt;&lt;/FUNCPTR&gt;&lt;/FUNCPTR&gt;&lt;/FUNCPTR&gt;&lt;/FUNCPTR&gt;&lt;/FUNCPTR&gt;&lt;/FUNCPTR&gt;&lt;/FUNCPTR&gt;&lt;/FUNCPTR&gt;&lt;/FUNCPTR&gt;&lt;/FUNCPTR&gt;&lt;/ISO_C_BINDING_MP_C_F_PROCPOINTER_&gt;&lt;/FUNCPTR&gt;&lt;/FUNCPTR&gt;&lt;/FUNCPTR&gt;&lt;/FUNCPTR&gt;&lt;/FUNCPTR&gt;&lt;/FUNCPTR&gt;&lt;/FUNCPTR&gt;&lt;/FUNCPTR&gt;&lt;/FUNCPTR&gt;&lt;/FUNCPTR&gt;</description>
      <pubDate>Wed, 24 Nov 2010 23:09:02 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Bugreport-Function-pointers-and-Fortran-2003-C-interoperability/m-p/750935#M7385</guid>
      <dc:creator>adrianinteldev</dc:creator>
      <dc:date>2010-11-24T23:09:02Z</dc:date>
    </item>
    <item>
      <title>Bugreport: Function pointers and Fortran 2003 C interoperabilit</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Bugreport-Function-pointers-and-Fortran-2003-C-interoperability/m-p/750936#M7386</link>
      <description>Unfortunately I will not be able to try it in that environment for a while. One of my colleagues, I am sure, can do so.</description>
      <pubDate>Thu, 25 Nov 2010 01:57:42 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Bugreport-Function-pointers-and-Fortran-2003-C-interoperability/m-p/750936#M7386</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2010-11-25T01:57:42Z</dc:date>
    </item>
    <item>
      <title>Bugreport: Function pointers and Fortran 2003 C interoperabilit</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Bugreport-Function-pointers-and-Fortran-2003-C-interoperability/m-p/750937#M7387</link>
      <description>Have you been able to run test on a 64-bit Linux machine in the meantime?</description>
      <pubDate>Wed, 08 Dec 2010 17:35:29 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Bugreport-Function-pointers-and-Fortran-2003-C-interoperability/m-p/750937#M7387</guid>
      <dc:creator>adrianinteldev</dc:creator>
      <dc:date>2010-12-08T17:35:29Z</dc:date>
    </item>
    <item>
      <title>Bugreport: Function pointers and Fortran 2003 C interoperabilit</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Bugreport-Function-pointers-and-Fortran-2003-C-interoperability/m-p/750938#M7388</link>
      <description>I believe that this problem is fixed in Update 4.</description>
      <pubDate>Fri, 27 May 2011 22:03:58 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Bugreport-Function-pointers-and-Fortran-2003-C-interoperability/m-p/750938#M7388</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2011-05-27T22:03:58Z</dc:date>
    </item>
  </channel>
</rss>

