<?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 problem with function returns from c++ in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/problem-with-function-returns-from-c/m-p/1119414#M131282</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Hopefully this should be easy...&lt;/P&gt;

&lt;P&gt;I'm using fortran to call a c++ function.&lt;/P&gt;

&lt;P&gt;This function returns the value 2 as a long - debugging shows this being set&amp;nbsp;&lt;/P&gt;

&lt;P&gt;But when it comes back into my integer4 fortran variable I see the return value as -2147483648&lt;/P&gt;

&lt;P&gt;Any thoughts about what might be going wrong?&lt;/P&gt;

&lt;P&gt;Very grateful for any assistance.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 15 Mar 2017 11:01:33 GMT</pubDate>
    <dc:creator>jim_cox</dc:creator>
    <dc:date>2017-03-15T11:01:33Z</dc:date>
    <item>
      <title>problem with function returns from c++</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/problem-with-function-returns-from-c/m-p/1119414#M131282</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Hopefully this should be easy...&lt;/P&gt;

&lt;P&gt;I'm using fortran to call a c++ function.&lt;/P&gt;

&lt;P&gt;This function returns the value 2 as a long - debugging shows this being set&amp;nbsp;&lt;/P&gt;

&lt;P&gt;But when it comes back into my integer4 fortran variable I see the return value as -2147483648&lt;/P&gt;

&lt;P&gt;Any thoughts about what might be going wrong?&lt;/P&gt;

&lt;P&gt;Very grateful for any assistance.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 11:01:33 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/problem-with-function-returns-from-c/m-p/1119414#M131282</guid>
      <dc:creator>jim_cox</dc:creator>
      <dc:date>2017-03-15T11:01:33Z</dc:date>
    </item>
    <item>
      <title>Can you show the code? It is</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/problem-with-function-returns-from-c/m-p/1119415#M131283</link>
      <description>&lt;P&gt;Can you show the code? It is very likely a mismatch in the interface as seen from both sides.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 11:07:15 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/problem-with-function-returns-from-c/m-p/1119415#M131283</guid>
      <dc:creator>Arjen_Markus</dc:creator>
      <dc:date>2017-03-15T11:07:15Z</dc:date>
    </item>
    <item>
      <title>fortran looks like:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/problem-with-function-returns-from-c/m-p/1119416#M131284</link>
      <description>&lt;P&gt;fortran looks like:&lt;/P&gt;

&lt;P&gt;INTEGER*4 LNS &amp;nbsp;&lt;/P&gt;

&lt;P&gt;LNS = SIDGETLANECT(%val(J2))&lt;/P&gt;

&lt;P&gt;c++&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;
	long __stdcall SIDGETLANECT(long origin)&lt;BR /&gt;
	{&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;CComPtr&amp;lt;ISIAPILegs&amp;gt; legs = NULL;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;CComPtr&amp;lt;ISIAPILeg&amp;gt; leg = NULL;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;CComPtr&amp;lt;ISIAPILaneApproachs&amp;gt; laneApprs = NULL;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;CComPtr&amp;lt;ISIAPILaneApproach&amp;gt; laneAppr = NULL;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;long b;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; site-&amp;gt;get_Legs(&amp;amp;legs);&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;legs-&amp;gt;get_Count(&amp;amp;b);&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;leg = NULL;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; legs-&amp;gt;get_Item(long (origin - 1) , &amp;amp;leg);&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if (leg == NULL) return 0;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;else&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;long laneApprCount, laneno;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;VARIANT_BOOL laneDisciplineExisting = false;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;leg-&amp;gt;get_LaneApproachs(&amp;amp;laneApprs);&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;laneApprs-&amp;gt;get_Count(&amp;amp;laneApprCount);&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;return laneApprCount ;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;BR /&gt;
	}&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 11:13:48 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/problem-with-function-returns-from-c/m-p/1119416#M131284</guid>
      <dc:creator>jim_cox</dc:creator>
      <dc:date>2017-03-15T11:13:48Z</dc:date>
    </item>
    <item>
      <title>But does the Fortran compiler</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/problem-with-function-returns-from-c/m-p/1119417#M131285</link>
      <description>&lt;P&gt;But does the Fortran compiler "know" that SIDGETLANECT is an integer function?&lt;/P&gt;

&lt;P&gt;If you do not declare it as such, via an interface block for instance, the default typing rules kick in an the function will be considered to return a floating-point number.&lt;/P&gt;

&lt;P&gt;Try:&lt;/P&gt;

&lt;P&gt;interface&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer function SIDGETLANECT(origin)&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer, value :: origin&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end function&lt;/P&gt;

&lt;P&gt;end interface&lt;/P&gt;

&lt;P&gt;or the like&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 11:42:32 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/problem-with-function-returns-from-c/m-p/1119417#M131285</guid>
      <dc:creator>Arjen_Markus</dc:creator>
      <dc:date>2017-03-15T11:42:32Z</dc:date>
    </item>
    <item>
      <title>You should also declare the C</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/problem-with-function-returns-from-c/m-p/1119418#M131286</link>
      <description>&lt;P&gt;You should also declare the C++ function as&lt;/P&gt;

&lt;P&gt;extern "C" { long SIDGETLANECT(long origin); } // function prototype&lt;/P&gt;

&lt;P&gt;See the IVF documentation: C/C++ Naming Conventions.&lt;BR /&gt;
	See also section under BIND&lt;/P&gt;

&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 11:55:19 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/problem-with-function-returns-from-c/m-p/1119418#M131286</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2017-03-15T11:55:19Z</dc:date>
    </item>
    <item>
      <title> </title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/problem-with-function-returns-from-c/m-p/1119419#M131287</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Sorry, its after midnight here and I probably should have also mentioned that&lt;/P&gt;

&lt;P&gt;the c++ function is in a separate library&lt;/P&gt;

&lt;P&gt;and&lt;/P&gt;

&lt;P&gt;that it has a .h function declaration&lt;/P&gt;

&lt;P&gt;extern "C" long __stdcall SIDGETLANECT(long origin);&lt;/P&gt;

&lt;P&gt;I will take a look at the interface definition in the morning&lt;/P&gt;

&lt;P&gt;Thanks for your input&lt;/P&gt;

&lt;P&gt;Jim&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 16:44:14 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/problem-with-function-returns-from-c/m-p/1119419#M131287</guid>
      <dc:creator>jim_cox</dc:creator>
      <dc:date>2017-03-15T16:44:14Z</dc:date>
    </item>
  </channel>
</rss>

