<?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 Re: Mixed languages in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixed-languages/m-p/764892#M19496</link>
    <description>In C, your CFUN returns a pointer to a string, one that is presumably allocated within the function.  You can do the same in Fortran.  The equivalent Fortran function would be something like this:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;&lt;BR /&gt;function CFUN()&lt;BR /&gt;integer(int_ptr_kind()) :: CFUN&lt;BR /&gt;character(10) :: retstr = 'abcdefghij'&lt;BR /&gt;integer(1), dimension(*) :: temp&lt;BR /&gt;pointer (p, temp)&lt;BR /&gt;&lt;BR /&gt;p = malloc (len(retstr)+1)&lt;BR /&gt;do i = 1,len(retstr)&lt;BR /&gt;  temp(i) = ichar(retstr(i:i)&lt;BR /&gt;  end do&lt;BR /&gt;temp(ubound(temp)) = 0&lt;BR /&gt;CFUN = P&lt;BR /&gt;return&lt;BR /&gt;end&lt;BR /&gt;&lt;/PRE&gt;&lt;BR /&gt;It's then the caller's responsibility to deallocate the result.</description>
    <pubDate>Wed, 15 Feb 2006 23:25:12 GMT</pubDate>
    <dc:creator>Steven_L_Intel1</dc:creator>
    <dc:date>2006-02-15T23:25:12Z</dc:date>
    <item>
      <title>Mixed languages</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixed-languages/m-p/764887#M19491</link>
      <description>&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;Steve Lionel has modified the C_CALL_Fortran mixed language samplefrom CVF into an IVF sample. &lt;/DIV&gt;
&lt;DIV&gt;The sample uses a FDLL project which builds the Fortran source of subroutine FSUBas a DLL. FSUB has an integer and a character string input argument and an character string output argument. FSUB concatenates the input arguments tooneoutput string.&lt;/DIV&gt;
&lt;DIV&gt;A c/c++ main programUSEDLL calls the dll version of FSUB.&lt;/DIV&gt;
&lt;DIV&gt;As an extension to this sample I am interested in ac/c++DLL project (say CDLL) in whichthe cdllsource codecontains (an entry of)a character function that calls the FSUB dll and returns thec string constructed by FSUB.&lt;/DIV&gt;
&lt;DIV&gt;Is that possible?&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;Giel&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 14 Feb 2006 23:21:33 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixed-languages/m-p/764887#M19491</guid>
      <dc:creator>Giel_H_</dc:creator>
      <dc:date>2006-02-14T23:21:33Z</dc:date>
    </item>
    <item>
      <title>Re: Mixed languages</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixed-languages/m-p/764888#M19492</link>
      <description>Most anything is possible, but I don't fully understand your specification.  How would you declare this C function in C? (Pretend Fortran isn't part of this.)  What does it mean to be a "character function" in C?</description>
      <pubDate>Tue, 14 Feb 2006 23:28:23 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixed-languages/m-p/764888#M19492</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2006-02-14T23:28:23Z</dc:date>
    </item>
    <item>
      <title>Re: Mixed languages</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixed-languages/m-p/764889#M19493</link>
      <description>&lt;DIV&gt;I admit that the use of "function" and "subroutine" is indeed confusing.&lt;/DIV&gt;
&lt;DIV&gt;Iwould suggest anything like:&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;LPTSTR CFUN&lt;/DIV&gt;
&lt;DIV&gt;LPSTR CFUN&lt;/DIV&gt;
&lt;DIV&gt;char *CFUN&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;And for the definition of the function CFUN:&lt;/DIV&gt;
&lt;DIV&gt;
&lt;DIV&gt;LPTSTR CFUN(int *int_arg,LPTSTR *str_in)&lt;/DIV&gt;
&lt;DIV&gt;
&lt;DIV&gt;
&lt;DIV&gt;LPSTR CFUN(int *int_arg,LPSTR *str_in)&lt;/DIV&gt;
&lt;DIV&gt;char *CFUN(int *int_arg, char *str_in)&lt;/DIV&gt;
&lt;DIV&gt;The body of the latter CFUN wouldbe something like&lt;/DIV&gt;
&lt;DIV&gt;{&lt;/DIV&gt;
&lt;DIV&gt; char *str_out;&lt;/DIV&gt;
&lt;DIV&gt; int STR_OUT_LEN;&lt;/DIV&gt;
&lt;DIV&gt; STR_OUT_LEN= 512;&lt;/DIV&gt;
&lt;DIV&gt; FSUB(&amp;amp;int_arg,str_in, str_out, strlen(str_in),STR_OUT_LEN);&lt;/DIV&gt;
&lt;DIV&gt; return str_out;&lt;/DIV&gt;
&lt;DIV&gt;}&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;Giel&lt;/DIV&gt;</description>
      <pubDate>Wed, 15 Feb 2006 17:29:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixed-languages/m-p/764889#M19493</guid>
      <dc:creator>Giel_H_</dc:creator>
      <dc:date>2006-02-15T17:29:59Z</dc:date>
    </item>
    <item>
      <title>Re: Mixed languages</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixed-languages/m-p/764890#M19494</link>
      <description>Uh-oh. You see, the problem with Fortran strings is that they-re two-fold: the passed information must always contain both the address and the length. Now, since both cannot be returned through registers, Fortran compiler "internally" turns the character-valued function into:&lt;BR /&gt;&lt;PRE&gt;FUNCTION StrRet()&lt;BR /&gt;CHARACTER(10):: StrRet&lt;BR /&gt;StrRet="1234567890"&lt;BR /&gt;END FUNCTION StrRet&lt;BR /&gt;&lt;BR /&gt;extern "C" char* strret(char*, int)&lt;/PRE&gt;Well, &lt;B&gt;maybe&lt;/B&gt;, I didn't care to do complete reverse-engineering. There are similar issues with functions returning TYPEs, arrays etc. So, it's better to avoid functions returning anything other than plain vanilla ints or floats in mixed-language programming.</description>
      <pubDate>Wed, 15 Feb 2006 19:24:55 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixed-languages/m-p/764890#M19494</guid>
      <dc:creator>Jugoslav_Dujic</dc:creator>
      <dc:date>2006-02-15T19:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: Mixed languages</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixed-languages/m-p/764891#M19495</link>
      <description>&lt;P&gt;OK. Exactly, therefore I would like to usethe CFUN. &lt;/P&gt;
&lt;P&gt;Giel&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 15 Feb 2006 23:06:01 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixed-languages/m-p/764891#M19495</guid>
      <dc:creator>Giel_H_</dc:creator>
      <dc:date>2006-02-15T23:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: Mixed languages</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixed-languages/m-p/764892#M19496</link>
      <description>In C, your CFUN returns a pointer to a string, one that is presumably allocated within the function.  You can do the same in Fortran.  The equivalent Fortran function would be something like this:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;&lt;BR /&gt;function CFUN()&lt;BR /&gt;integer(int_ptr_kind()) :: CFUN&lt;BR /&gt;character(10) :: retstr = 'abcdefghij'&lt;BR /&gt;integer(1), dimension(*) :: temp&lt;BR /&gt;pointer (p, temp)&lt;BR /&gt;&lt;BR /&gt;p = malloc (len(retstr)+1)&lt;BR /&gt;do i = 1,len(retstr)&lt;BR /&gt;  temp(i) = ichar(retstr(i:i)&lt;BR /&gt;  end do&lt;BR /&gt;temp(ubound(temp)) = 0&lt;BR /&gt;CFUN = P&lt;BR /&gt;return&lt;BR /&gt;end&lt;BR /&gt;&lt;/PRE&gt;&lt;BR /&gt;It's then the caller's responsibility to deallocate the result.</description>
      <pubDate>Wed, 15 Feb 2006 23:25:12 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Mixed-languages/m-p/764892#M19496</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2006-02-15T23:25:12Z</dc:date>
    </item>
  </channel>
</rss>

