<?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 String length argument isn't correctly passed from Fortran to C++ function in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/String-length-argument-isn-t-correctly-passed-from-Fortran-to-C/m-p/829257#M51561</link>
    <description>I'm using the latest Intel Visual Fortran Compiler (ver 11.1.060 update 5) with Visual Studio 2008 profesional edition on Windows XP. I found there's a potential bug in the lastest Intel Visual Fortran Compiler, which didn't exist in previous versions. The bug causes problem passing the string length from Fortran to C functions. You know, when calling C functions with string arguments in Fortran program, the compiler appends the length of the string(s) to the end of the argument list (see &lt;A href="http://docs.hp.com/en/B3909-90002/ch08s05.html)" target="_blank"&gt;http://docs.hp.com/en/B3909-90002/ch08s05.html)&lt;/A&gt;. Somehow, the value of the string length isn't correctly passed to C or C++ function with the latest Fortran Compiler.   &lt;BR /&gt;   &lt;BR /&gt;I tried the following code with both the compiler versions "11.1.060 update 5" and "11.0.061". The code worked properly when compiled with version "11.0.061". It failed during run-time when compiled with version "11.1.060 update 5". The source code and solution file are also attached.   &lt;BR /&gt;   &lt;BR /&gt;---- C++ code -------------   &lt;BR /&gt;#include &lt;IOSTREAM&gt;   &lt;BR /&gt;using namespace std;   &lt;BR /&gt;   &lt;BR /&gt;extern "C"   &lt;BR /&gt;{   &lt;BR /&gt;void fix_string_for_f90(char s[], long int len)   &lt;BR /&gt;{   &lt;BR /&gt;int i;   &lt;BR /&gt;   &lt;BR /&gt;for (i = strlen(s); i &amp;lt; len; i++)   &lt;BR /&gt;s&lt;I&gt; = ' ';   &lt;BR /&gt;}   &lt;BR /&gt;   &lt;BR /&gt;void print_string(char s[], long int len)   &lt;BR /&gt;{   &lt;BR /&gt;cout &amp;lt;&amp;lt; "String printed in C: " &amp;lt;&amp;lt; endl;   &lt;BR /&gt;cout &amp;lt;&amp;lt; s &amp;lt;&amp;lt; endl;   &lt;BR /&gt;fix_string_for_f90(s,len);   &lt;BR /&gt;}   &lt;BR /&gt;}   &lt;BR /&gt;   &lt;BR /&gt;--------- Fortran code ------------------   &lt;BR /&gt;   &lt;BR /&gt;program string_test   &lt;BR /&gt;   &lt;BR /&gt;INTERFACE   &lt;BR /&gt;SUBROUTINE print_string(string) BIND (C,NAME = "print_string")   &lt;BR /&gt;CHARACTER(LEN=*) :: string   &lt;BR /&gt;END SUBROUTINE print_string   &lt;BR /&gt;END INTERFACE   &lt;BR /&gt;   &lt;BR /&gt;character(100) :: string   &lt;BR /&gt;   &lt;BR /&gt;string = "Hello World."//char(0)   &lt;BR /&gt;CALL print_string(string)   &lt;BR /&gt;   &lt;BR /&gt;WRITE(*,*) " String printed in Fortran: "   &lt;BR /&gt;WRITE(*,*) TRIM(string)   &lt;BR /&gt;   &lt;BR /&gt;end program string_test   &lt;BR /&gt;&lt;BR /&gt;&lt;/I&gt;&lt;/IOSTREAM&gt;</description>
    <pubDate>Fri, 30 Apr 2010 21:55:25 GMT</pubDate>
    <dc:creator>Wuwei_L_</dc:creator>
    <dc:date>2010-04-30T21:55:25Z</dc:date>
    <item>
      <title>String length argument isn't correctly passed from Fortran to C++ function</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/String-length-argument-isn-t-correctly-passed-from-Fortran-to-C/m-p/829257#M51561</link>
      <description>I'm using the latest Intel Visual Fortran Compiler (ver 11.1.060 update 5) with Visual Studio 2008 profesional edition on Windows XP. I found there's a potential bug in the lastest Intel Visual Fortran Compiler, which didn't exist in previous versions. The bug causes problem passing the string length from Fortran to C functions. You know, when calling C functions with string arguments in Fortran program, the compiler appends the length of the string(s) to the end of the argument list (see &lt;A href="http://docs.hp.com/en/B3909-90002/ch08s05.html)" target="_blank"&gt;http://docs.hp.com/en/B3909-90002/ch08s05.html)&lt;/A&gt;. Somehow, the value of the string length isn't correctly passed to C or C++ function with the latest Fortran Compiler.   &lt;BR /&gt;   &lt;BR /&gt;I tried the following code with both the compiler versions "11.1.060 update 5" and "11.0.061". The code worked properly when compiled with version "11.0.061". It failed during run-time when compiled with version "11.1.060 update 5". The source code and solution file are also attached.   &lt;BR /&gt;   &lt;BR /&gt;---- C++ code -------------   &lt;BR /&gt;#include &lt;IOSTREAM&gt;   &lt;BR /&gt;using namespace std;   &lt;BR /&gt;   &lt;BR /&gt;extern "C"   &lt;BR /&gt;{   &lt;BR /&gt;void fix_string_for_f90(char s[], long int len)   &lt;BR /&gt;{   &lt;BR /&gt;int i;   &lt;BR /&gt;   &lt;BR /&gt;for (i = strlen(s); i &amp;lt; len; i++)   &lt;BR /&gt;s&lt;I&gt; = ' ';   &lt;BR /&gt;}   &lt;BR /&gt;   &lt;BR /&gt;void print_string(char s[], long int len)   &lt;BR /&gt;{   &lt;BR /&gt;cout &amp;lt;&amp;lt; "String printed in C: " &amp;lt;&amp;lt; endl;   &lt;BR /&gt;cout &amp;lt;&amp;lt; s &amp;lt;&amp;lt; endl;   &lt;BR /&gt;fix_string_for_f90(s,len);   &lt;BR /&gt;}   &lt;BR /&gt;}   &lt;BR /&gt;   &lt;BR /&gt;--------- Fortran code ------------------   &lt;BR /&gt;   &lt;BR /&gt;program string_test   &lt;BR /&gt;   &lt;BR /&gt;INTERFACE   &lt;BR /&gt;SUBROUTINE print_string(string) BIND (C,NAME = "print_string")   &lt;BR /&gt;CHARACTER(LEN=*) :: string   &lt;BR /&gt;END SUBROUTINE print_string   &lt;BR /&gt;END INTERFACE   &lt;BR /&gt;   &lt;BR /&gt;character(100) :: string   &lt;BR /&gt;   &lt;BR /&gt;string = "Hello World."//char(0)   &lt;BR /&gt;CALL print_string(string)   &lt;BR /&gt;   &lt;BR /&gt;WRITE(*,*) " String printed in Fortran: "   &lt;BR /&gt;WRITE(*,*) TRIM(string)   &lt;BR /&gt;   &lt;BR /&gt;end program string_test   &lt;BR /&gt;&lt;BR /&gt;&lt;/I&gt;&lt;/IOSTREAM&gt;</description>
      <pubDate>Fri, 30 Apr 2010 21:55:25 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/String-length-argument-isn-t-correctly-passed-from-Fortran-to-C/m-p/829257#M51561</guid>
      <dc:creator>Wuwei_L_</dc:creator>
      <dc:date>2010-04-30T21:55:25Z</dc:date>
    </item>
    <item>
      <title>String length argument isn't correctly passed from Fortran to C</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/String-length-argument-isn-t-correctly-passed-from-Fortran-to-C/m-p/829258#M51562</link>
      <description>The code worked "properly" in the older compilers because the compiler had a bug which matched the bug in your code. The compiler's bug was fixed - now it's your turn. &lt;BR /&gt;&lt;BR /&gt;Here's how it was described in the release notes. The reference to Update 2 is not quite correct - some of these changes did not appear until later. (Why you are referencing an HP manual is puzzling - and note that the HP manual does not make any reference to BIND(C).)&lt;BR /&gt;&lt;BR /&gt;---&lt;BR /&gt;&lt;BR /&gt;Earlier versions of the Intel Fortran Compiler incorrectly passed or used hidden arguments for&lt;BR /&gt;procedures with the BIND(C) attribute. For example, if a Fortran routine had a CHARACTER&lt;BR /&gt;argument and had BIND(C) specified, the compiler would assume that two hidden arguments&lt;BR /&gt;were passed for the function return address and length, plus another hidden argument for each&lt;BR /&gt;character argument. While such hidden arguments are necessary and correct for noninteroperable&lt;BR /&gt;(without the BIND(C) attribute) Fortran procedures, the Fortran standard prohibits&lt;BR /&gt;them for interoperable procedures. The Fortran and C argument list must have a 1:1&lt;BR /&gt;correspondence.&lt;BR /&gt;&lt;BR /&gt;In many cases where this problem occurs, the procedure does not meet the standards rules for&lt;BR /&gt;interoperable procedures. For example, if an argument is of type CHARACTER, the length&lt;BR /&gt;must be 1  an array of such characters may be an argument. Arrays of any nature are not&lt;BR /&gt;permitted as function return values for interoperable procedures. However, it is possible to&lt;BR /&gt;create a standard-conforming interoperable procedure for which the compiler was passing or&lt;BR /&gt;expecting hidden arguments.&lt;BR /&gt;&lt;BR /&gt;In 11.1 Update 2, the compiler has been corrected to no longer pass or expect hidden&lt;BR /&gt;arguments. If you wrote C code which assumed that such hidden arguments needed to be&lt;BR /&gt;passed you will have to rewrite it and recompile. You may find that in some cases, functions will&lt;BR /&gt;need to be converted to subroutines with the result variable passed as an actual argument. We&lt;BR /&gt;apologize for the inconvenience, but it is important for correctness and portability to have this&lt;BR /&gt;error repaired.&lt;BR /&gt;&lt;BR /&gt;---&lt;BR /&gt;&lt;BR /&gt;Note also the comment that CHARACTER arguments with length other than 1 are "not interoperable" in the eyes of the standard. You can declare the argument as an array of CHARACTER(1) values and still pass a character string to it.</description>
      <pubDate>Fri, 30 Apr 2010 22:53:17 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/String-length-argument-isn-t-correctly-passed-from-Fortran-to-C/m-p/829258#M51562</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2010-04-30T22:53:17Z</dc:date>
    </item>
  </channel>
</rss>

