<?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 Passing strings to C++ from ifort 12 in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Passing-strings-to-C-from-ifort-12/m-p/921143#M85526</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;In the following code snippet I notice that string lengths are passed to C++ differently:&lt;/P&gt;
&lt;P&gt;[fortran]&lt;BR /&gt;type MyPro&lt;BR /&gt;character(len=256) :: path&lt;BR /&gt;end type&amp;nbsp;&lt;/P&gt;
&lt;P&gt;subroutine Test&lt;BR /&gt;implicit none&lt;/P&gt;
&lt;P&gt;type(MyPro):: Pro&lt;BR /&gt;character(len=256):: path&amp;nbsp;&lt;BR /&gt;integer::err&lt;BR /&gt;&lt;BR /&gt;!these call directly C++ functions defined as&lt;BR /&gt;! void dbGet(const char *key, char *pValue, int *err, size_t key_len, size_t value_len)&lt;BR /&gt;!&lt;BR /&gt;call dbGet("Path", Pro%path, err)&amp;nbsp;&lt;BR /&gt;call dbGet("Path", path, err)&amp;nbsp;&lt;BR /&gt;end subroutine&lt;BR /&gt;[/fortran]&lt;/P&gt;
&lt;P&gt;The problem is that on the C++ side value_len gets a 0 value from the first fortran call, but the correct value from the second call.&lt;BR /&gt;&amp;nbsp;I would appreciate an explanation for this,&lt;BR /&gt;&lt;BR /&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 04 Apr 2013 19:38:03 GMT</pubDate>
    <dc:creator>Dimitrios_T_</dc:creator>
    <dc:date>2013-04-04T19:38:03Z</dc:date>
    <item>
      <title>Passing strings to C++ from ifort 12</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Passing-strings-to-C-from-ifort-12/m-p/921143#M85526</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;In the following code snippet I notice that string lengths are passed to C++ differently:&lt;/P&gt;
&lt;P&gt;[fortran]&lt;BR /&gt;type MyPro&lt;BR /&gt;character(len=256) :: path&lt;BR /&gt;end type&amp;nbsp;&lt;/P&gt;
&lt;P&gt;subroutine Test&lt;BR /&gt;implicit none&lt;/P&gt;
&lt;P&gt;type(MyPro):: Pro&lt;BR /&gt;character(len=256):: path&amp;nbsp;&lt;BR /&gt;integer::err&lt;BR /&gt;&lt;BR /&gt;!these call directly C++ functions defined as&lt;BR /&gt;! void dbGet(const char *key, char *pValue, int *err, size_t key_len, size_t value_len)&lt;BR /&gt;!&lt;BR /&gt;call dbGet("Path", Pro%path, err)&amp;nbsp;&lt;BR /&gt;call dbGet("Path", path, err)&amp;nbsp;&lt;BR /&gt;end subroutine&lt;BR /&gt;[/fortran]&lt;/P&gt;
&lt;P&gt;The problem is that on the C++ side value_len gets a 0 value from the first fortran call, but the correct value from the second call.&lt;BR /&gt;&amp;nbsp;I would appreciate an explanation for this,&lt;BR /&gt;&lt;BR /&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2013 19:38:03 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Passing-strings-to-C-from-ifort-12/m-p/921143#M85526</guid>
      <dc:creator>Dimitrios_T_</dc:creator>
      <dc:date>2013-04-04T19:38:03Z</dc:date>
    </item>
    <item>
      <title>We need more details about</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Passing-strings-to-C-from-ifort-12/m-p/921144#M85527</link>
      <description>&lt;P&gt;We need more details about how you compile and which compiler versions you use, as well as actual source code to demonstrate the problem. Using the attached files and IFort/Icl 13.1.1.171, in the debugger I see 4 and 256 inside DBGET for key_len and value_len during both calls to DBGET.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2013 21:49:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Passing-strings-to-C-from-ifort-12/m-p/921144#M85527</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2013-04-04T21:49:00Z</dc:date>
    </item>
    <item>
      <title>This looks like a calling</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Passing-strings-to-C-from-ifort-12/m-p/921145#M85528</link>
      <description>&lt;P&gt;This looks like a calling mechanism problem since Fortran doesn't know anything about C++ - it just has a standard way to interface with C. Is your program 32 or 64 bit? As far as I know there is only one calling convention on 64-bit whereas there is a whole plethora of them in 32-bit. I believe the standard is now to have a 1:1 correspondence between Fortran and C argument lists - no more hidden arguments. So with the right calling convention (or in 64-bit) you should be able to do&lt;/P&gt;
&lt;P&gt;[fortran]&lt;/P&gt;
&lt;P&gt;call dbGet("Path", Pro%path, err, len("Path"), len(Pro%path))&lt;/P&gt;
&lt;P&gt;[/fortran]&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2013 14:07:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Passing-strings-to-C-from-ifort-12/m-p/921145#M85528</guid>
      <dc:creator>Simon_Geard</dc:creator>
      <dc:date>2013-04-05T14:07:35Z</dc:date>
    </item>
    <item>
      <title>I seem to be unable to post</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Passing-strings-to-C-from-ifort-12/m-p/921146#M85529</link>
      <description>&lt;P&gt;I seem to be unable to post the full text of my update here, so I attach it as a text file.&lt;BR /&gt;Please download and read,&lt;BR /&gt;&lt;BR /&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2013 17:16:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Passing-strings-to-C-from-ifort-12/m-p/921146#M85529</guid>
      <dc:creator>Dimitrios_T_</dc:creator>
      <dc:date>2013-04-05T17:16:00Z</dc:date>
    </item>
    <item>
      <title>In your case 2 (type embedded</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Passing-strings-to-C-from-ifort-12/m-p/921147#M85530</link>
      <description>&lt;P&gt;In your case 2 (type embedded), the NULL char you observed after the string is likely accidental.&lt;/P&gt;
&lt;P&gt;type MyPro&amp;nbsp; &lt;BR /&gt;character(len=256) :: path&amp;nbsp; &lt;BR /&gt;integer :: flag&lt;BR /&gt;end type&lt;/P&gt;
&lt;P&gt;Initialize path as before, but set flag to -1.&lt;/P&gt;
&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Sat, 06 Apr 2013 12:35:15 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Passing-strings-to-C-from-ifort-12/m-p/921147#M85530</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2013-04-06T12:35:15Z</dc:date>
    </item>
    <item>
      <title>Thanks Jim, I checked with</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Passing-strings-to-C-from-ifort-12/m-p/921148#M85531</link>
      <description>&lt;P&gt;Thanks Jim, I checked with various stack data around the fortran type and it was indeed accidental. This leaves the #2 issue still unsolved.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2013 11:58:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Passing-strings-to-C-from-ifort-12/m-p/921148#M85531</guid>
      <dc:creator>Dimitrios_T_</dc:creator>
      <dc:date>2013-04-08T11:58:00Z</dc:date>
    </item>
    <item>
      <title>I suggest that since your C++</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Passing-strings-to-C-from-ifort-12/m-p/921149#M85532</link>
      <description>&lt;P&gt;I suggest that since your C++ side interface explicitly uses a size argument that you declare the C++ interface on the FORTRAN side with explicit size arguments as sgearg suggests.&lt;/P&gt;
&lt;P&gt;Note, you can create a shell function in FORTRAN that is passed (key,value,err) which calls the C++ function with&amp;nbsp; (key,value,err, LEN(key), LEN(value)). Or use LENTRIM in place of LEN.&lt;/P&gt;
&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2013 14:33:56 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Passing-strings-to-C-from-ifort-12/m-p/921149#M85532</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2013-04-08T14:33:56Z</dc:date>
    </item>
    <item>
      <title>Thanks everyone, I finally</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Passing-strings-to-C-from-ifort-12/m-p/921150#M85533</link>
      <description>&lt;P&gt;Thanks everyone, I finally found a workaround without extra size arguments.since the general issue is to pass any type, array or string. My interface code depends on a custom data mining tool that extracts types from fortran files and their dependent embedded types (if any) and generates binary-compatible C++ structures. It also creates appropriate metadata describing each type, members, descriptors, sizes, etc. These structs have exactly the same size as the fortran types, so I use the metadata to extract the size of anything, including strings. I know, this deviates from my original question, but the issue was more general.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2013 22:03:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Passing-strings-to-C-from-ifort-12/m-p/921150#M85533</guid>
      <dc:creator>Dimitrios_T_</dc:creator>
      <dc:date>2013-04-12T22:03:51Z</dc:date>
    </item>
  </channel>
</rss>

