<?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 Using allocatable, target variables in derived types with ISO_C_BINDING in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-allocatable-target-variables-in-derived-types-with-ISO-C/m-p/921666#M85637</link>
    <description>&lt;P&gt;I'm binding Fortran code with a C dll, and I would like to have a Fortran array inter-operable with C. I currently have the following subroutine to bind the Fortran array with a C double*:&lt;/P&gt;
&lt;P&gt;SUBROUTINE Pack_Inputs( Input , In_X )&lt;BR /&gt; TYPE( InputType ) , INTENT(INOUT) :: Input&lt;BR /&gt; REAL(KIND=C_DOUBLE) , ALLOCATABLE , TARGET , INTENT(INOUT) :: In_X(:)&lt;BR /&gt; &lt;BR /&gt; IF ( .NOT. ALLOCATED(In_X) ) ALLOCATE( In_X (Input%Xlen) )&lt;BR /&gt; &lt;BR /&gt; DO i = 1,Input%C_obj%Xlen &lt;BR /&gt; In_X(i) = Input%X(i)&lt;BR /&gt; END DO&lt;BR /&gt; Input%C_obj%X = C_LOC(In_X) &lt;BR /&gt; END SUBROUTINE Pack_Inputs&lt;/P&gt;
&lt;P&gt;However, what I don't like about the current state of code is that I am constantly allocating memory, and having to unpack the array when the C dll is entered (partly driven by my reluctance to use the `SAVE` attribute on `In_X(:)`). I would rather much declare `In_X` once, inside a Fortran derived type. This leads to the motivation for this post. In this derived type:&lt;/P&gt;
&lt;P&gt;USE , INSTRINSIC :: ISO_C_BINDING&lt;/P&gt;
&lt;P&gt;TYPE , PUBLIC :: InputType &lt;BR /&gt; TYPE(InputType_C) &amp;nbsp; :: C_obj &lt;BR /&gt; REAL(KIND=C_DOUBLE) , ALLOCATABLE , TARGET :: In_X(:) &lt;BR /&gt; REAL , DIMENSION(:) , ALLOCATABLE :: X &lt;BR /&gt; REAL , DIMENSION(:) , ALLOCATABLE :: Y &lt;BR /&gt; REAL , DIMENSION(:) , ALLOCATABLE :: Z &lt;BR /&gt; INTEGER , DIMENSION(:) , ALLOCATABLE :: index&lt;BR /&gt; INTEGER :: Xlen &lt;BR /&gt; INTEGER :: Ylen &lt;BR /&gt; INTEGER :: Zlen &lt;BR /&gt; INTEGER :: indexlen&lt;BR /&gt; END TYPE InputType&lt;/P&gt;
&lt;P&gt;But this leads to the error:&lt;/P&gt;
&lt;P&gt;error #6516: This attribute specification is not valid for a component definition statement. &amp;nbsp; [TARGET]&lt;/P&gt;
&lt;P&gt;because of TARGET. &amp;nbsp;Is there a pathway to get around this issue?&lt;/P&gt;</description>
    <pubDate>Fri, 14 Jun 2013 19:07:11 GMT</pubDate>
    <dc:creator>mdmas</dc:creator>
    <dc:date>2013-06-14T19:07:11Z</dc:date>
    <item>
      <title>Using allocatable, target variables in derived types with ISO_C_BINDING</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-allocatable-target-variables-in-derived-types-with-ISO-C/m-p/921666#M85637</link>
      <description>&lt;P&gt;I'm binding Fortran code with a C dll, and I would like to have a Fortran array inter-operable with C. I currently have the following subroutine to bind the Fortran array with a C double*:&lt;/P&gt;
&lt;P&gt;SUBROUTINE Pack_Inputs( Input , In_X )&lt;BR /&gt; TYPE( InputType ) , INTENT(INOUT) :: Input&lt;BR /&gt; REAL(KIND=C_DOUBLE) , ALLOCATABLE , TARGET , INTENT(INOUT) :: In_X(:)&lt;BR /&gt; &lt;BR /&gt; IF ( .NOT. ALLOCATED(In_X) ) ALLOCATE( In_X (Input%Xlen) )&lt;BR /&gt; &lt;BR /&gt; DO i = 1,Input%C_obj%Xlen &lt;BR /&gt; In_X(i) = Input%X(i)&lt;BR /&gt; END DO&lt;BR /&gt; Input%C_obj%X = C_LOC(In_X) &lt;BR /&gt; END SUBROUTINE Pack_Inputs&lt;/P&gt;
&lt;P&gt;However, what I don't like about the current state of code is that I am constantly allocating memory, and having to unpack the array when the C dll is entered (partly driven by my reluctance to use the `SAVE` attribute on `In_X(:)`). I would rather much declare `In_X` once, inside a Fortran derived type. This leads to the motivation for this post. In this derived type:&lt;/P&gt;
&lt;P&gt;USE , INSTRINSIC :: ISO_C_BINDING&lt;/P&gt;
&lt;P&gt;TYPE , PUBLIC :: InputType &lt;BR /&gt; TYPE(InputType_C) &amp;nbsp; :: C_obj &lt;BR /&gt; REAL(KIND=C_DOUBLE) , ALLOCATABLE , TARGET :: In_X(:) &lt;BR /&gt; REAL , DIMENSION(:) , ALLOCATABLE :: X &lt;BR /&gt; REAL , DIMENSION(:) , ALLOCATABLE :: Y &lt;BR /&gt; REAL , DIMENSION(:) , ALLOCATABLE :: Z &lt;BR /&gt; INTEGER , DIMENSION(:) , ALLOCATABLE :: index&lt;BR /&gt; INTEGER :: Xlen &lt;BR /&gt; INTEGER :: Ylen &lt;BR /&gt; INTEGER :: Zlen &lt;BR /&gt; INTEGER :: indexlen&lt;BR /&gt; END TYPE InputType&lt;/P&gt;
&lt;P&gt;But this leads to the error:&lt;/P&gt;
&lt;P&gt;error #6516: This attribute specification is not valid for a component definition statement. &amp;nbsp; [TARGET]&lt;/P&gt;
&lt;P&gt;because of TARGET. &amp;nbsp;Is there a pathway to get around this issue?&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2013 19:07:11 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-allocatable-target-variables-in-derived-types-with-ISO-C/m-p/921666#M85637</guid>
      <dc:creator>mdmas</dc:creator>
      <dc:date>2013-06-14T19:07:11Z</dc:date>
    </item>
    <item>
      <title>TARGET is an attribute for</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-allocatable-target-variables-in-derived-types-with-ISO-C/m-p/921667#M85638</link>
      <description>&lt;P&gt;TARGET is an attribute for variables, not for components of a derived type.&lt;/P&gt;
&lt;P&gt;I am not completely sure what you are doing here. Where is Pack_Inputs called from?&amp;nbsp; ALLOCATABLE arrays are not interoperable with C. (Neither are POINTER arrays.)&amp;nbsp; You could use TYPE(C_PTR) as a component - it might then make sense to use a POINTER array to allocate the storage, and then use C_LOC to get the address to store into the C_PTR. Coming in to Fortran you can use C_F_POINTER to map that to a Fortran POINTER. I am not sure this is relevant to what you're doing - can you explain in more detail? Maybe provide some C code as context?&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2013 19:45:53 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Using-allocatable-target-variables-in-derived-types-with-ISO-C/m-p/921667#M85638</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2013-06-14T19:45:53Z</dc:date>
    </item>
  </channel>
</rss>

