<?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 how to access common block data from c in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/how-to-access-common-block-data-from-c/m-p/825878#M49987</link>
    <description>Add extern "C" to the declaration of the struct on the C++ side.&lt;BR /&gt;&lt;BR /&gt;Consider using BIND(C) to specify the external name of the common block. This should also remove any need to go a #pragma pack'ing. Consider using C_DOUBLE as the kind of the reals that are in the common block.&lt;BR /&gt;&lt;BR /&gt;Note that you can interop with normal module variables too. Common blocks are an anachronism.&lt;BR /&gt;</description>
    <pubDate>Fri, 10 Sep 2010 20:30:35 GMT</pubDate>
    <dc:creator>IanH</dc:creator>
    <dc:date>2010-09-10T20:30:35Z</dc:date>
    <item>
      <title>how to access common block data from c</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/how-to-access-common-block-data-from-c/m-p/825877#M49986</link>
      <description>&lt;P&gt;I am doing a mixed c/fortran project and has a problem for accessing fortran common block from c&lt;BR /&gt;&lt;BR /&gt;uisng the intel fortran mixed language example as below.&lt;BR /&gt;&lt;BR /&gt;There is a common block kwaves in fortran program, and I want to access the data x, y in c++ program, when I debug this project, in the c subroutine, I can see that the kwaves has the address, but it does not show as a struct and I can not access to its data. Anyone know why?&lt;BR /&gt;&lt;BR /&gt;zhiling LI&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Fortran part:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;PROGRAM fmain&lt;BR /&gt;IMPLICIT NONE&lt;/P&gt;&lt;P&gt;INTERFACE&lt;BR /&gt; SUBROUTINE c_routine (int_arg, str_in, str_out) BIND(C)&lt;BR /&gt; USE,INTRINSIC :: ISO_C_BINDING ! Declares C kinds&lt;BR /&gt; INTEGER(C_INT), VALUE,INTENT(IN) :: int_arg&lt;BR /&gt; CHARACTER(KIND=C_CHAR),DIMENSION(*) :: str_in,str_out&lt;BR /&gt; END SUBROUTINE c_routine&lt;BR /&gt;END INTERFACE&lt;BR /&gt;real*8 x, y&lt;BR /&gt;!DEC$ ATTRIBUTES alias :'kwaves'::kwaves&lt;/P&gt;&lt;P&gt; common /kwaves/ x, y&lt;BR /&gt;&lt;BR /&gt;CHARACTER(80) OUTPUT_TEXT&lt;BR /&gt;INTEGER IN_ARG, OUTPUT_LEN&lt;BR /&gt;CHARACTER(80) INPUT_TEXT&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;INPUT_TEXT = "Testing..."C ! C suffix adds a null terminator&lt;BR /&gt;IN_ARG = 123&lt;/P&gt;&lt;P&gt;x=1.0&lt;BR /&gt;CALL c_routine (in_arg, input_text, output_text)&lt;/P&gt;&lt;P&gt;OUTPUT_LEN = INDEX(OUTPUT_TEXT," ")&lt;BR /&gt;IF (OUTPUT_LEN == 0) OUTPUT_LEN = 80&lt;/P&gt;&lt;P&gt;WRITE (*,*) OUTPUT_TEXT(1:OUTPUT_LEN)&lt;/P&gt;&lt;P&gt;END&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: x-small;"&gt;&lt;SPAN style="color: #0000ff; font-size: x-small;"&gt;C part&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#pragma pack(2)&lt;/STDIO.H&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; extern struct kwaves_type&lt;BR /&gt;{&lt;BR /&gt;double x, y;&lt;BR /&gt;}kwaves;&lt;BR /&gt;#pragma pack()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;extern "C" void c_routine (&lt;BR /&gt; int int_arg,&lt;BR /&gt; char* input_text,&lt;BR /&gt; char* output_text//,&lt;BR /&gt;//struct kwaves_type *kwaves1&lt;BR /&gt; )&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt; sprintf(output_text,"%s%i ",input_text,int_arg);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Sep 2010 18:08:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/how-to-access-common-block-data-from-c/m-p/825877#M49986</guid>
      <dc:creator>lizhiling98</dc:creator>
      <dc:date>2010-09-10T18:08:38Z</dc:date>
    </item>
    <item>
      <title>how to access common block data from c</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/how-to-access-common-block-data-from-c/m-p/825878#M49987</link>
      <description>Add extern "C" to the declaration of the struct on the C++ side.&lt;BR /&gt;&lt;BR /&gt;Consider using BIND(C) to specify the external name of the common block. This should also remove any need to go a #pragma pack'ing. Consider using C_DOUBLE as the kind of the reals that are in the common block.&lt;BR /&gt;&lt;BR /&gt;Note that you can interop with normal module variables too. Common blocks are an anachronism.&lt;BR /&gt;</description>
      <pubDate>Fri, 10 Sep 2010 20:30:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/how-to-access-common-block-data-from-c/m-p/825878#M49987</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2010-09-10T20:30:35Z</dc:date>
    </item>
    <item>
      <title>how to access common block data from c</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/how-to-access-common-block-data-from-c/m-p/825879#M49988</link>
      <description>thanks. it solve my problem.&lt;BR /&gt;&lt;BR /&gt;Best wishes,&lt;BR /&gt;Zhiling LI</description>
      <pubDate>Mon, 13 Sep 2010 12:50:16 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/how-to-access-common-block-data-from-c/m-p/825879#M49988</guid>
      <dc:creator>lizhiling98</dc:creator>
      <dc:date>2010-09-13T12:50:16Z</dc:date>
    </item>
  </channel>
</rss>

