<?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 When Tim says &amp;quot;f2008&amp;quot; here he in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174669#M146982</link>
    <description>&lt;P&gt;When Tim says "f2008" here he really means Fortran 2018 (formerly Fortran 2015), or the "Additional Interoperability of Fortran with C" Technical Specification 29113, which Intel Fortran 16 and later supports. I agree with Tim that these features, while quite powerful, are far beyond what you need here and add complexity to the C implementation.&lt;/P&gt;</description>
    <pubDate>Fri, 15 Dec 2017 20:16:50 GMT</pubDate>
    <dc:creator>Steve_Lionel</dc:creator>
    <dc:date>2017-12-15T20:16:50Z</dc:date>
    <item>
      <title>How to pass data/pointer between C/C++ and Fortran code?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174663#M146976</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;

&lt;P&gt;I am trying to compile some code that can work on Linux system to Windows 7 64bit + VS2013 + Intel Fortran. I have successfully compiled the code but the data are not passed correctly. For example, the following are Fortran code and C code:&lt;/P&gt;

&lt;P&gt;Fortran:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;      pointer (pptr,prolog), (eptr,epilog)
      integer prolog(*), epilog(*)
 
      include 'mm2000.h'
 
      integer array_bytes, block_bytes
      integer index, j, iptrsize
...
      pptr = util_malloc(block_bytes)
&lt;/PRE&gt;

&lt;P&gt;C:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;void* UTIL_MALLOC(long long nbytes)
{ /* util_malloc  */
	void* iptout = NULL;

  if(!(iptout= malloc(nbytes))) {
    printf("UTIL_MALLOC: Out of memory, malloc return: %p \n",iptout);
    printf("   Requested value: %f = %4d bit unsigned int \n",(float)nbytes,sizeof(nbytes));
    return NULL;

  } /* if */

  return iptout;
} /* util_malloc */
&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Now the data are pass from Fortran to C, In Fortran side block_bytes=416, but in C the nbytes=1625144.&lt;/P&gt;

&lt;P&gt;Another C example:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;int_ptrsize UTIL_SUM_ADDR(long long* a, long long* b)
{ /* util_sum_addr */
  return *a + *b;
} /* util_sum_addr */

void* UTIL_REALLOC(void** iptr, long long* nwords)
{ /* util_realloc */
  void* iptout = NULL;
  long long nbytes = 0;

  nbytes = (*nwords);

  if (!(iptout= realloc(*iptr,nbytes))) {
    printf("UTIL_REALLOC: Reallocation error - aborting\n");
    printf("   Requested value: %f = %4d bit unsigned int \n",(float)nbytes,sizeof(nbytes));

    /*  exit(1); */
    return NULL;

  } /* if */

  return iptout;
} /* util_realloc */
&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;In Fortran code, the function is as follows:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;      pointer (pptr,prolog), (eptr,epilog)
      integer prolog(*), epilog(*)
       integer array_bytes, block_bytes, iptrsize
...
      pptr = util_realloc(pptr, block_bytes)
      eptr = util_sum_addr(aptr, array_bytes)
&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;How to modify C/Fortran code to let the function be executed correctly?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;

&lt;P&gt;Tang Laoya&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2017 08:23:53 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174663#M146976</guid>
      <dc:creator>Zhanghong_T_</dc:creator>
      <dc:date>2017-12-14T08:23:53Z</dc:date>
    </item>
    <item>
      <title>A c pointer is equivalent to</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174664#M146977</link>
      <description>A c pointer is equivalent to what is referred to in ifort as integer pointer and in other Fortran compilers as Cray pointer. Your ifort is too old to support the f2008 portability features but you do need to look up earlier facilities like bind(c) and c_f_pointer. The latter intrinsic makes a Fortran pointer from the properly sized integer pointer.</description>
      <pubDate>Thu, 14 Dec 2017 13:16:57 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174664#M146977</guid>
      <dc:creator>TimP</dc:creator>
      <dc:date>2017-12-14T13:16:57Z</dc:date>
    </item>
    <item>
      <title>I betcha mm2000.h has an</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174665#M146978</link>
      <description>&lt;P&gt;I betcha mm2000.h has an interface block that looks like this:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;interface
&amp;nbsp;&amp;nbsp; function UTIL_MALLOC(nbytes)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; use ISO_C_BINDING
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; implicit none
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer(C_LONG_LONG), value :: nbytes
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer(C_INTPTR_T) UTIL_MALLOC
&amp;nbsp;&amp;nbsp; end function UTIL_MALLOC
end interface
&lt;/PRE&gt;

&lt;P&gt;gfortran, for example, would pass nbytes by value in this context, but current ifort does not. You need to specify the BIND property for the function if you want ifort to pass truly by value:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;interface
&amp;nbsp;&amp;nbsp; function UTIL_MALLOC(nbytes) bind(C,name='UTIL_MALLOC')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; use ISO_C_BINDING
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; implicit none
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer(C_LONG_LONG), value :: nbytes
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer(C_INTPTR_T) UTIL_MALLOC
&amp;nbsp;&amp;nbsp; end function UTIL_MALLOC
end interface

&lt;/PRE&gt;

&lt;P&gt;See if that helps. Also, I would recommend getting rid of the Cray pointers and replacing them with type(C_PTR) to communicate with C and Fortran pointers to dereference them on the Fortran side. If all you are trying to achieve is dynamic memory allocation, then you might be able to just do away with the C function to do that entirely and use allocatables in Fortran.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2017 15:37:54 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174665#M146978</guid>
      <dc:creator>JVanB</dc:creator>
      <dc:date>2017-12-14T15:37:54Z</dc:date>
    </item>
    <item>
      <title>Dear Repeat Offender,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174666#M146979</link>
      <description>&lt;P&gt;Dear &lt;A href="https://software.intel.com/en-us/user/197269"&gt;Repeat Offender,&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Thank you very much for your kindly reply. I will study the interface you provided. Could you also give me some hints on how to write interface for the function &lt;CODE class="plain"&gt;UTIL_SUM_ADDR?&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Yes, the Fortran code is just from mm2000.F, and the C code is from mmsc.c, I guess that the author is use the C++ to manage memory for Fortran code. I am trying to modify the code to let it work in Windows and Intel Fortran.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;

&lt;P&gt;Tang Laoya&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2017 00:07:42 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174666#M146979</guid>
      <dc:creator>Zhanghong_T_</dc:creator>
      <dc:date>2017-12-15T00:07:42Z</dc:date>
    </item>
    <item>
      <title>Dear Tim,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174667#M146980</link>
      <description>&lt;P&gt;Dear Tim,&lt;/P&gt;

&lt;P&gt;Thank you very much for your kindly reply. Do you mean that if the compiler support Fortran 2008, the interface would be much simpiler? I noticed that IVF 2018 support Fortran 2008, I will try it latter.&lt;/P&gt;

&lt;P&gt;Another question: if I build the above code by IVF 2018 as a static library, Can I link the library to the executabe file compiled by IVF 2016?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;

&lt;P&gt;Tang Laoya&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2017 00:10:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174667#M146980</guid>
      <dc:creator>Zhanghong_T_</dc:creator>
      <dc:date>2017-12-15T00:10:00Z</dc:date>
    </item>
    <item>
      <title>No, f2008 provides access to</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174668#M146981</link>
      <description>No, f2008 provides access to the details of Fortran pointer, but that may not simplify your task.</description>
      <pubDate>Fri, 15 Dec 2017 06:44:30 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174668#M146981</guid>
      <dc:creator>TimP</dc:creator>
      <dc:date>2017-12-15T06:44:30Z</dc:date>
    </item>
    <item>
      <title>When Tim says "f2008" here he</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174669#M146982</link>
      <description>&lt;P&gt;When Tim says "f2008" here he really means Fortran 2018 (formerly Fortran 2015), or the "Additional Interoperability of Fortran with C" Technical Specification 29113, which Intel Fortran 16 and later supports. I agree with Tim that these features, while quite powerful, are far beyond what you need here and add complexity to the C implementation.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2017 20:16:50 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174669#M146982</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2017-12-15T20:16:50Z</dc:date>
    </item>
    <item>
      <title>Dear Steve,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174670#M146983</link>
      <description>&lt;P&gt;Dear Steve,&lt;/P&gt;

&lt;P&gt;Thank you very much for your kindly reply. It seems that I still need to provide interface for these C functions. How to write interface for this kind of function?&lt;/P&gt;

&lt;P&gt;&lt;CODE class="keyword bold"&gt;void&lt;/CODE&gt;&lt;CODE class="plain"&gt;* UTIL_REALLOC(&lt;/CODE&gt;&lt;CODE class="keyword bold"&gt;void&lt;/CODE&gt;&lt;CODE class="plain"&gt;** iptr, &lt;/CODE&gt;&lt;CODE class="color1 bold"&gt;long&lt;/CODE&gt; &lt;CODE class="color1 bold"&gt;long&lt;/CODE&gt;&lt;CODE class="plain"&gt;* nwords)&lt;/CODE&gt;&lt;CODE&gt;;&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;Thanks,&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;Tang Laoya&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Dec 2017 00:59:03 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174670#M146983</guid>
      <dc:creator>Zhanghong_T_</dc:creator>
      <dc:date>2017-12-17T00:59:03Z</dc:date>
    </item>
    <item>
      <title>interface</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174671#M146984</link>
      <description>&lt;PRE class="brush:fortran;"&gt;interface
  use, intrinsic :: iso_c_binding
  subroutine UTL_REALLOC (iptr, nwords) bind(C,NAME="UTL_REALLOC")
    type(C_PTR), intent(INOUT) :: iptr
    integer(C_LONG), intent(INOUT) :: nwords
  end subroutine UTL_REALLOC
end interface&lt;/PRE&gt;

&lt;P&gt;iptr is a pointer passed by reference - presumably it gets updated by the function. nwords is also passed by reference but I don't know if the function changes it.&lt;/P&gt;

&lt;P&gt;You can then use C_F_POINTER from module ISO_C_BINDING to convert iptr to a Fortran pointer. (And use C_LOC to go the other way.)&lt;/P&gt;</description>
      <pubDate>Sun, 17 Dec 2017 17:53:49 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174671#M146984</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2017-12-17T17:53:49Z</dc:date>
    </item>
    <item>
      <title>Dear Steve,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174672#M146985</link>
      <description>&lt;P&gt;Dear Steve,&lt;/P&gt;

&lt;P&gt;Thank you very much for your kindly reply. I am trying to rewrite the code. The original Fortran code is as follows:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;      pointer (aptr,char_array)
      character*32 char_array(*)
      pointer (pptr,prolog), (eptr,epilog)
      integer prolog(*), epilog(*)
...
      aptr =  util_sum_addr(pptr, PROLOG_BYTES)
      eptr =  util_sum_addr(aptr, array_bytes)
&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;The original C code is as follows:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;long long UTIL_SUM_ADDR(long long* a, long long* b)
{ /* util_sum_addr */
  return *a + *b;
} /* util_sum_addr */
&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;I added the following interface in the Fortran code:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;      interface
	  function UTIL_SUM_ADDR(a,b) bind(C,name='UTIL_SUM_ADDR')
	  use ISO_C_BINDING
	  implicit none
	  integer(C_LONG), intent(INOUT) :: a,b
	  integer(C_LONG_LONG) :: UTIL_SUM_ADDR
	  end function UTIL_SUM_ADDR
      end interface      
&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;When compiling, the following error displayed:&lt;/P&gt;

&lt;P&gt;Error&amp;nbsp;&amp;nbsp; &amp;nbsp;4&amp;nbsp;&amp;nbsp; &amp;nbsp; error #6633: The type of the actual argument differs from the type of the dummy argument.&amp;nbsp;&amp;nbsp; [APTR]&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;
	Error&amp;nbsp;&amp;nbsp; &amp;nbsp;2&amp;nbsp;&amp;nbsp; &amp;nbsp; error #6633: The type of the actual argument differs from the type of the dummy argument.&amp;nbsp;&amp;nbsp; [PPTR]&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;
	Error&amp;nbsp;&amp;nbsp; &amp;nbsp;3&amp;nbsp;&amp;nbsp; &amp;nbsp; error #6638: An actual argument is an expression or constant; this is not valid since the associated dummy argument has the explicit INTENT(OUT) or INTENT(INOUT) attribute.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;What else should I modify in the Fortran code?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;

&lt;P&gt;Tang Laoya&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2017 02:05:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174672#M146985</guid>
      <dc:creator>Zhanghong_T_</dc:creator>
      <dc:date>2017-12-18T02:05:40Z</dc:date>
    </item>
    <item>
      <title>You don't need pointers at</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174673#M146986</link>
      <description>&lt;P&gt;You don't need pointers at all in this latest example - just pass the variables by reference like you would to a Fortran routine. Your interface is wrong, though, in that you declare the arguments C_LONG instead of C_LONG_LONG. Also it appears you are passing a constant where you declared the dummy argument INTENT(INOUT). In this case you may want to omit INTENT.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2017 02:14:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174673#M146986</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2017-12-18T02:14:59Z</dc:date>
    </item>
    <item>
      <title>Dear Steve,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174674#M146987</link>
      <description>&lt;P&gt;Dear Steve,&lt;/P&gt;

&lt;P&gt;Thank you very much for your kindly reply. As you suggested, after removed INTENT(INOUT), the compiling was successed, but the following warning displayed:&lt;/P&gt;

&lt;P&gt;warning #6075: The data type of the actual argument does not match the definition.&amp;nbsp;&amp;nbsp; [ARRAY_BYTES]&lt;/P&gt;

&lt;P&gt;I don't know whether data can be passed correctly.&lt;/P&gt;

&lt;P&gt;What do you mean "You don't need pointers at all in this latest example"? For example, the variable "&lt;CODE class="plain"&gt;aptr&lt;/CODE&gt;", which pointed to a character, how to declare that variable without pointers?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;

&lt;P&gt;Tang Laoya&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2017 02:48:09 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174674#M146987</guid>
      <dc:creator>Zhanghong_T_</dc:creator>
      <dc:date>2017-12-18T02:48:09Z</dc:date>
    </item>
    <item>
      <title>Dear Steve,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174675#M146988</link>
      <description>&lt;P&gt;Dear Steve,&lt;/P&gt;

&lt;P&gt;In the Fortran code, the code is as follows:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;      pointer (pptr,prolog), (eptr,epilog)
      integer prolog(*), epilog(*)
...
      pptr = util_realloc(pptr, block_bytes)
&lt;/PRE&gt;

&lt;P&gt;The C code is as follows:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;void* UTIL_REALLOC(void** iptr, long long* nwords)
{ /* util_realloc */
  void* iptout = NULL;
  long long nbytes = 0;

  nbytes = (*nwords);

  if (!(iptout= realloc(*iptr,nbytes))) {
    printf("UTIL_REALLOC: Reallocation error - aborting\n");
    printf("   Requested value: %f = %4d bit unsigned int \n",(float)nbytes,sizeof(nbytes));

    /*  exit(1); */
    return NULL;

  } /* if */

  return iptout;
} /* util_realloc */
&lt;/PRE&gt;

&lt;P&gt;I added the interface for 'UTIL_REALLOC' as you suggested:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;	  function UTIL_REALLOC(iptr,nwords) bind(C,name='UTIL_REALLOC')
	  use ISO_C_BINDING
	  implicit none
	  type(C_PTR), intent(INOUT) :: iptr
	  integer(C_LONG_LONG) :: nwords
	  integer(C_INTPTR_T) UTIL_REALLOC
	  end function UTIL_REALLOC
&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;The following compiling error displayed:&lt;/P&gt;

&lt;P&gt;error #6633: The type of the actual argument differs from the type of the dummy argument.&amp;nbsp;&amp;nbsp; [PPTR]&lt;/P&gt;

&lt;P&gt;What should I modify in Fortran code to let it work?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;

&lt;P&gt;Tang Laoya&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2017 08:48:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174675#M146988</guid>
      <dc:creator>Zhanghong_T_</dc:creator>
      <dc:date>2017-12-18T08:48:00Z</dc:date>
    </item>
    <item>
      <title>You are not showing all the</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174676#M146989</link>
      <description>&lt;P&gt;You are not showing all the declarations nor the part of the code that causes the error.&lt;/P&gt;

&lt;P&gt;My comment that you didn't need the pointers for UTIL_SUM_ADDR was that this function simply takes two "long long" variables by reference and adds them. From the Fortran perspective, this is just like passing integer variables normally. You didn't show all the code (nor all the declarations), so I can't be sure what the purpose of this function really is. If you had other reasons to pass pointers, then you could declare the arguments to UTIL_SUM_ADDR to be integer(C_INTPTR_T) and also include the VALUE attribute. This would get the right level of indirection on the C side and would allow you to keep using integer pointers.&lt;/P&gt;

&lt;P&gt;Now that I see more of your use of UTIL_REALLOC, I'd suggest changing the iptr dummy argument in the Fortran interface from type(C_PTR) to integer(C_INTPTR_T). You shouldn't need other changes.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2017 16:01:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174676#M146989</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2017-12-18T16:01:00Z</dc:date>
    </item>
    <item>
      <title>Dear Steve,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174677#M146990</link>
      <description>&lt;P&gt;Dear Steve,&lt;/P&gt;

&lt;P&gt;I am sorry that I have not shown all related code. Now I attached the related source files, could you please help me to take a look at it? To let it work and to keep original code, I used macro 'ivfwin'.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;

&lt;P&gt;Tang Laoya&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2017 23:13:07 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174677#M146990</guid>
      <dc:creator>Zhanghong_T_</dc:creator>
      <dc:date>2017-12-18T23:13:07Z</dc:date>
    </item>
    <item>
      <title>Dear Steve,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174678#M146991</link>
      <description>&lt;P&gt;Dear Steve,&lt;/P&gt;

&lt;P&gt;In fact, I am trying to build LaGriT (https://github.com/lanl/LaGriT) in Visual Studio 2013 + IVF 2016 environment. I created two projects-one is C++ static library and another is Fortran console project. The C++ static library include all c code in \src and \ &lt;SPAN class="css-truncate css-truncate-target"&gt;&lt;A class="js-navigation-open" href="https://github.com/lanl/LaGriT/tree/master/lg_util/src" id="31083411e1f3f6ad18d876b9318b50d5-91a40ba7a208c4fecf89473de15dc392e0120f26" title="This path skips through empty directories"&gt;&lt;SPAN class="simplified-path"&gt;lg_util/&lt;/SPAN&gt;src&amp;nbsp;&lt;/A&gt;&lt;/SPAN&gt;folders and the&lt;SPAN class="css-truncate css-truncate-target"&gt;&lt;A class="js-navigation-open" href="https://github.com/lanl/LaGriT/tree/master/lg_util/src" title="This path skips through empty directories"&gt; &lt;/A&gt;&lt;/SPAN&gt;Fortran console project include all Fortran code, and when link to executable file the C++ static library is included. By simply build these two projects, hundreds of errors will display. I modified many Fortran files to let the build succeed.&lt;/P&gt;

&lt;P&gt;But now there are some data pass problems between C and Fortran code. Could you please help me to take a look at it?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;

&lt;P&gt;Tang Laoya&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 04:39:32 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174678#M146991</guid>
      <dc:creator>Zhanghong_T_</dc:creator>
      <dc:date>2017-12-19T04:39:32Z</dc:date>
    </item>
    <item>
      <title>Sorry, but I don't have the</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174679#M146992</link>
      <description>&lt;P&gt;Sorry, but I don't have the time to analyze your large program in such detail.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 16:16:16 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174679#M146992</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2017-12-19T16:16:16Z</dc:date>
    </item>
    <item>
      <title>Dear Steve,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174680#M146993</link>
      <description>&lt;P&gt;Dear Steve,&lt;/P&gt;

&lt;P&gt;I am sorry for late reply. I simplified the original project to a small one and attached the whole simplified solution under VS2013+Intel Parallel Studio 2016. The C project generate a static library which would be linked by the Fortran project. The following error displayed if I build the solution:&lt;/P&gt;

&lt;P&gt;Error&amp;nbsp;&amp;nbsp; &amp;nbsp;4&amp;nbsp;&amp;nbsp; &amp;nbsp; error #6633: The type of the actual argument differs from the type of the dummy argument.&amp;nbsp;&amp;nbsp; [ADAPTR]&amp;nbsp;&amp;nbsp;&amp;nbsp; .\testmem.f90&amp;nbsp;&amp;nbsp; &amp;nbsp;75&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;
	Error&amp;nbsp;&amp;nbsp; &amp;nbsp;2&amp;nbsp;&amp;nbsp; &amp;nbsp; error #6633: The type of the actual argument differs from the type of the dummy argument.&amp;nbsp;&amp;nbsp; [ADNPTR]&amp;nbsp;&amp;nbsp;&amp;nbsp; .\testmem.f90&amp;nbsp;&amp;nbsp; &amp;nbsp;74&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;
	Error&amp;nbsp;&amp;nbsp; &amp;nbsp;6&amp;nbsp;&amp;nbsp; &amp;nbsp; error #6633: The type of the actual argument differs from the type of the dummy argument.&amp;nbsp;&amp;nbsp; [LPTR]&amp;nbsp;&amp;nbsp;&amp;nbsp; .\testmem.f90&amp;nbsp;&amp;nbsp; &amp;nbsp;76&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/P&gt;

&lt;P&gt;Could you please help me to take a look at the problem?&lt;/P&gt;

&lt;P&gt;In addition: after commented out the lines that 'util_realloc' was called, the following errors displayed:&lt;/P&gt;

&lt;P&gt;Error&amp;nbsp;&amp;nbsp; &amp;nbsp;1&amp;nbsp;&amp;nbsp; &amp;nbsp; error #11018: Cannot open mem_c.lib&amp;nbsp;&amp;nbsp; &amp;nbsp;ipo&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;
	Error&amp;nbsp;&amp;nbsp; &amp;nbsp;2&amp;nbsp;&amp;nbsp; &amp;nbsp; fatal error LNK1181: cannot open input file 'mem_c.lib'&amp;nbsp;&amp;nbsp; &amp;nbsp;LINK&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/P&gt;

&lt;P&gt;The build only success when I put a copy of mem_c.lib to '.\testmem' directory (that is to say, two mem_c.lib should be existed in '.\Debug' and '.\testmem' at the same time). Could you please tell me what lead to this problem?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;

&lt;P&gt;Tang Laoya&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Dec 2017 06:43:44 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174680#M146993</guid>
      <dc:creator>Zhanghong_T_</dc:creator>
      <dc:date>2017-12-25T06:43:44Z</dc:date>
    </item>
    <item>
      <title>The Fortran error messages</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174681#M146994</link>
      <description>&lt;P&gt;The Fortran error messages are because you have the iptr argument in the interface to UTL_REALLOC declared as type(C_PTR), but it should instead be integer(C_INTPTR_T) as you are passing an integer pointer.&lt;/P&gt;

&lt;P&gt;Another error is that the nwords argument is declared as C_LONG_LONG) but in the program you pass a default integer argument. If you declare max_ad as integer(C_LONG_LONG) it will fix that. (You will need to add "use, intrinsic :: ISO_C_BINDING" to the main program.) I am concerned also about the declaration of ad_addr as the comment says "pointer-sized integer" but it is declared as default integer. You don't use that in this smaller example so I'm not sure how this is used.&lt;/P&gt;

&lt;P&gt;When I build the solution with these changes, the compile errors go away (I get a conversion warning from C++ that I am ignoring, but I then get a link error for the printf reference in the C code. I'm not a C/C++ expert - doing some web searching tells me that Microsoft changed the way printf was implemented in VS2015 and later (I have 2017), but as best as I can tell you're properly including stdio.h so I don't know what else is the problem. You could ask in a Microsoft C++ forum for help with that. I can see that a workaround is to add&amp;nbsp;legacy_stdio_definitions.lib to "Linker &amp;gt; Additional Dependencies" in the Fortran project - that allows the program to link successfully.&lt;/P&gt;

&lt;P&gt;I suspect that the IPO error you're seeing for mem_c.lib is because you have it listed as an additional dependency in the Fortran project. Since the C++ project is a dependent of the Fortran project, mem_c.lib gets linked in automatically. Since you don't tell the linker where to look for additional libraries, it can't find it. Just delete the mem_c.lib from there and let the build system take care of it through project dependencies. (Note that while this automatic linking works for C++ static libraries referenced from Fortran, Microsot changes prevent it from working for DLL libraries as well as any non-C++ libraries referenced from the C++ project.)&lt;/P&gt;</description>
      <pubDate>Mon, 25 Dec 2017 15:48:19 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174681#M146994</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2017-12-25T15:48:19Z</dc:date>
    </item>
    <item>
      <title>Quote:Zhanghong T. wrote:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174682#M146995</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;Zhanghong T. wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;..&amp;nbsp;&lt;SPAN style="font-size: 1em;"&gt;Could you please help me to take a look at the problem? ..&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;@Tang Laoya,&lt;/P&gt;

&lt;P&gt;What exactly you're trying to do!?&lt;/P&gt;

&lt;P&gt;It's very surprising no one has thus far pointed out to you assumed-size array declarations (e.g., &lt;SPAN style="font-size: 13.008px;"&gt;character*32 ad_name(2,*))&amp;nbsp;&lt;/SPAN&gt;are only allowed as dummy arguments whereas you are trying to declare them as such for a local variable as in your testmem program.&lt;/P&gt;

&lt;P&gt;It would also appear you're trying to write your own wrapper routines around standard C library functions such as malloc, realloc, etc. or trying to use someone else's wrappers for the same.&amp;nbsp; Note you don't need to do such a thing, you can directly use them from Fortran.&amp;nbsp; I suggest if you are interested in learning better about Fortran, you review sources referenced in this blog by Steve Lionel:&amp;nbsp;&lt;SPAN style="font-size: 13.008px;"&gt;&lt;A href="https://software.intel.com/en-us/blogs/2013/12/30/doctor-fortran-in-its-a-modern-fortran-world" target="_blank"&gt;https://software.intel.com/en-us/blogs/2013/12/30/doctor-fortran-in-its-a-modern-fortran-world&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 13.008px;"&gt;In the meantime, note you can do the following:&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 13.008px;"&gt;mem-c.c file: a simple file that shows a C function to printf some memory:&lt;/SPAN&gt;&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#include &amp;lt;stdio.h&amp;gt;

void Cout(void *str) {
   printf("%s\n", (char *)str);
}&lt;/PRE&gt;

&lt;P&gt;Fortran module defining interface to C stdlib function(s) and the above one:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;module mem2000

   use, intrinsic :: iso_c_binding, only : c_char, c_ptr, c_size_t

   implicit none

   private

   interface

      function realloc( ptr, new_size ) result(ret) bind(C,name="realloc")
      ! Defined in C header &amp;lt;stdlib.h&amp;gt;
      ! void *realloc( void *ptr, size_t new_size );

         import :: c_ptr, c_size_t
         
         implicit none
         
         ! Argument list
         type(c_ptr), intent(in), value :: ptr
         integer(c_size_t), intent(in), value :: new_size
         ! Function result
         type(c_ptr) :: ret
         
      end function realloc

      subroutine Cout( vptr ) bind(C, name="Cout")
      
         import :: c_ptr
         
         implicit none
         
         ! Argument list
         type(c_ptr), intent(in), value :: vptr
         
      end subroutine Cout
      
      subroutine free( vptr ) bind(C, name="free")
      ! Defined in header &amp;lt;stdlib.h&amp;gt;
      ! void free( void* ptr );
      
         import :: c_ptr
         
         implicit none
         
         ! Argument list
         type(c_ptr), intent(in), value :: vptr
         
      end subroutine free
      
   end interface

   public :: realloc
   public :: Cout
   public :: free
   
end module mem2000&lt;/PRE&gt;

&lt;P&gt;And a main program in Fortran:&amp;nbsp;&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;!****************************************************************************
!
!  PROGRAM: testmem
!
!  PURPOSE:  Entry point for the console application.
!
!****************************************************************************
program testmem

   use, intrinsic :: iso_c_binding, only : c_size_t, c_char, c_null_char, c_ptr, c_null_ptr,        &amp;amp;
                                           c_f_pointer
   use mem2000, only : realloc, Cout, free

   implicit none

   integer(c_size_t), parameter :: NUM_AD_START = 1
   integer(c_size_t), parameter :: SIZE_1 = 2
   integer(c_size_t), parameter :: BYTES_PER_CHAR = 32

   type(c_ptr) :: adnptr
   integer(c_size_t) :: nbytes
   character(kind=c_char,len=BYTES_PER_CHAR), pointer :: ad_name(:,:)

   adnptr = c_null_ptr
   nbytes = NUM_AD_START*SIZE_1*BYTES_PER_CHAR
   adnptr = realloc(adnptr, nbytes) ! Allocate the C pointer
   
   ! Setup a Fortran pointer to point to the C pointer
   call c_f_pointer( cptr=adnptr, fptr=ad_name, shape=[SIZE_1, NUM_AD_START] )
   
   ! Load some data into allocated memory
   ad_name(1,1) = repeat(string=c_char_"x", ncopies=BYTES_PER_CHAR-1) // new_line(c_char_"")
   ad_name(2,1) = c_char_"Hello World! Testing char *" // c_null_char
   
   ! Output the memory using a C function
   call Cout( adnptr )
   
   ! Nullify the Fortran pointer
   ad_name =&amp;gt; null()
   
   call free( adnptr ) ! Free the C pointer

   stop

end program testmem&lt;/PRE&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em;"&gt;If you manage to compile and link the above either from a suitable command prompt or using a Visual Studio solution, say with Fortran console and C static library projects, you should get output along the following lines:&lt;/SPAN&gt;&lt;/P&gt;

&lt;PRE class="brush:plain;"&gt;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hello World! Testing char *&lt;/PRE&gt;

&lt;P&gt;Attached find a zip file with an example&amp;nbsp;Visual Studio solution with a Fortran console and C static library projects.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Dec 2017 22:36:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-pass-data-pointer-between-C-C-and-Fortran-code/m-p/1174682#M146995</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2017-12-26T22:36:38Z</dc:date>
    </item>
  </channel>
</rss>

