<?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 Thanks! in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-length-character-array-and-bind-c-subroutine/m-p/1008560#M105458</link>
    <description>&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Wed, 18 Mar 2015 16:04:46 GMT</pubDate>
    <dc:creator>Allen_Barnett</dc:creator>
    <dc:date>2015-03-18T16:04:46Z</dc:date>
    <item>
      <title>Implicit length character array and bind(c) subroutine</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-length-character-array-and-bind-c-subroutine/m-p/1008552#M105450</link>
      <description>&lt;P&gt;We recently updated to IFORT 15.0.2.179. A few of the regression tests for our code system now fail. The basic pattern is calling a function written in C with a slice of a two-dimensional character array; the compiler is not passing a pointer to the correct word in the character array. Here is a reduced example; we declare an interface to the C routine and iterate over the rows of a character array, passing the first column to the C function:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;module r
  interface
     subroutine cprint ( leng, chars ) bind (c)
       use, intrinsic :: iso_c_binding, only : c_int, c_char
       integer(kind=c_int) :: leng
       character(kind=c_char,len=1) :: chars( leng )
     end subroutine cprint
  end interface
end module r

subroutine b ( leng, chars )
  use r
  integer :: leng, i
  character(len=*) :: chars( leng, 2 )
  do i = 1, 2
     call cprint( leng, chars(:,i) )
  end do
end subroutine b

program a
  integer, parameter :: leng = 23
  integer :: i
  character(len=1) :: chars( leng, 2 )
  character(len=leng) :: buffer
  buffer = 'ABCDEFGHIJ'
  do i = 1, leng
     chars(i,1) = buffer(i:i)
  end do
  buffer = '1234567890'
  do i = 1, leng
     chars(i,2) = buffer(i:i)
  end do
  call b( leng, chars )
end program a
&lt;/PRE&gt;

&lt;P&gt;and the C++ subroutine:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#include &amp;lt;cstdio&amp;gt;
extern "C" void cprint ( const int* leng, const char* chars )
{
  for ( int i = 0; i &amp;lt; *leng; ++i ) {
    putc( chars&lt;I&gt;, stdout );
  }
  putc( '\n', stdout );
  fflush( stdout );
}
&lt;/I&gt;&lt;/PRE&gt;

&lt;P&gt;I expect this to print:&lt;/P&gt;

&lt;PRE class="brush:plain;"&gt;ABCDEFGHIJ
1234567890&lt;/PRE&gt;

&lt;P&gt;But instead I get:&lt;/P&gt;

&lt;PRE class="brush:plain;"&gt;ABCDEFGHIJ
ABCDEFGHIJ&lt;/PRE&gt;

&lt;P&gt;If I look at the assembly code for subroutine b, it appears that the correct address for chars(:,i) is not being computed; it just uses the same address for each iteration.&lt;/P&gt;

&lt;P&gt;Variations: If I replace character(len=*) with character(len=1) in subroutine b, the correct strings are printed by cprint. If I leave in (len=*) but call a Fortran print subroutine with the same arguments, the correct strings are printed.&lt;/P&gt;

&lt;P&gt;I tried my example program with ifort 14.0.4.237 and it also prints the incorrect strings. But, our main program, which is lot larger, works correctly. Kind of odd.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
	Allen&lt;/P&gt;</description>
      <pubDate>Thu, 12 Feb 2015 19:16:48 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-length-character-array-and-bind-c-subroutine/m-p/1008552#M105450</guid>
      <dc:creator>Allen_Barnett</dc:creator>
      <dc:date>2015-02-12T19:16:48Z</dc:date>
    </item>
    <item>
      <title>Your example does not pass an</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-length-character-array-and-bind-c-subroutine/m-p/1008553#M105451</link>
      <description>&lt;P&gt;Your example does not pass an array slice to C.&lt;/P&gt;

&lt;P&gt;Did you mean to use:&lt;/P&gt;

&lt;P&gt;&lt;CODE class="keyword"&gt;call&lt;/CODE&gt; &lt;CODE class="plain"&gt;b( leng, chars(:,1) )&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;&lt;CODE class="keyword"&gt;call&lt;/CODE&gt; &lt;CODE class="plain"&gt;b( leng, chars(:,2) )&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Feb 2015 20:10:26 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-length-character-array-and-bind-c-subroutine/m-p/1008553#M105451</guid>
      <dc:creator>Andrew_Smith</dc:creator>
      <dc:date>2015-02-12T20:10:26Z</dc:date>
    </item>
    <item>
      <title>Hmm. It's supposed to pass</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-length-character-array-and-bind-c-subroutine/m-p/1008554#M105452</link>
      <description>&lt;P&gt;Hmm. It's supposed to pass the 2D array to subroutine b and then a slice of that is passed on to the C function cprint.&amp;nbsp; Does it not do that?&lt;BR /&gt;
	Allen&lt;BR /&gt;
	&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Feb 2015 20:18:53 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-length-character-array-and-bind-c-subroutine/m-p/1008554#M105452</guid>
      <dc:creator>Allen_Barnett</dc:creator>
      <dc:date>2015-02-12T20:18:53Z</dc:date>
    </item>
    <item>
      <title>Interesting. Declaring "chars</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-length-character-array-and-bind-c-subroutine/m-p/1008555#M105453</link>
      <description>&lt;P&gt;Interesting. Declaring "chars" in subroutine b as len=1 rather than len=* gives the correct behavior, even though they should be the same here. We'll take a look.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Feb 2015 20:39:56 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-length-character-array-and-bind-c-subroutine/m-p/1008555#M105453</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2015-02-12T20:39:56Z</dc:date>
    </item>
    <item>
      <title>I can go back to version 12.1</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-length-character-array-and-bind-c-subroutine/m-p/1008556#M105454</link>
      <description>&lt;P&gt;I can go back to version 12.1 and still see the bad behavior. Which compiler version did you use where you got the results you like?&lt;/P&gt;</description>
      <pubDate>Thu, 12 Feb 2015 20:50:43 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-length-character-array-and-bind-c-subroutine/m-p/1008556#M105454</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2015-02-12T20:50:43Z</dc:date>
    </item>
    <item>
      <title>Our main code has had this</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-length-character-array-and-bind-c-subroutine/m-p/1008557#M105455</link>
      <description>&lt;P&gt;Our main code has had this idiom for a long time, probably since version 11, and it has always worked until 15.0.&amp;nbsp; The compiler has never complained.&lt;/P&gt;

&lt;P&gt;We've been reading the Fortran standard and it probably is an error to use len=*, but it has worked as-is for a long time.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
	Allen&lt;/P&gt;</description>
      <pubDate>Thu, 12 Feb 2015 21:01:20 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-length-character-array-and-bind-c-subroutine/m-p/1008557#M105455</guid>
      <dc:creator>Allen_Barnett</dc:creator>
      <dc:date>2015-02-12T21:01:20Z</dc:date>
    </item>
    <item>
      <title>No, it's not an error to use</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-length-character-array-and-bind-c-subroutine/m-p/1008558#M105456</link>
      <description>&lt;P&gt;No, it's not an error to use len=* - b is not a bind(c) routine. I escalated this as issue&amp;nbsp;DPD200366425 - I tried all compilers back to 12.1 and got the same bad results. Very puzzling. Removing bind(c) from cprint (which is declared correctly) also corrects the behavior.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Feb 2015 21:14:36 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-length-character-array-and-bind-c-subroutine/m-p/1008558#M105456</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2015-02-12T21:14:36Z</dc:date>
    </item>
    <item>
      <title>This has been fixed for a</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-length-character-array-and-bind-c-subroutine/m-p/1008559#M105457</link>
      <description>&lt;P&gt;This has been fixed for a release later this year.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2015 15:33:29 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-length-character-array-and-bind-c-subroutine/m-p/1008559#M105457</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2015-03-18T15:33:29Z</dc:date>
    </item>
    <item>
      <title>Thanks!</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-length-character-array-and-bind-c-subroutine/m-p/1008560#M105458</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2015 16:04:46 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Implicit-length-character-array-and-bind-c-subroutine/m-p/1008560#M105458</guid>
      <dc:creator>Allen_Barnett</dc:creator>
      <dc:date>2015-03-18T16:04:46Z</dc:date>
    </item>
  </channel>
</rss>

