title: Using allocatable, target variables in a derived type
body: <p>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*:</p>
  
  <pre><code>SUBROUTINE Pack_Inputs( Input , In_X )
    TYPE( InputType ) ,               INTENT(INOUT)            :: Input
    REAL(KIND=C_DOUBLE) , ALLOCATABLE , TARGET , INTENT(INOUT) :: In_X(:)
  
    IF ( .NOT. ALLOCATED(In_X)     ) ALLOCATE( In_X    (Input%Xlen)     )
  
    DO i = 1,Input%C_obj%Xlen       
       In_X(i) = Input%X(i)
    END DO
    Input%C_obj%X = C_LOC(In_X)    
  END SUBROUTINE Pack_Inputs
  </code></pre>
  
  <p>However, what I don't like about the current 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 <code>SAVE</code> attribute on <code>In_X(:)</code>).  I would rather much declare  <code>In_X</code> once, inside a Fortran derived type. This leads to the motivation for this post. In this derived type:</p>
  
  <pre><code>USE , INSTRINSIC :: ISO_C_BINDING
  
  TYPE , PUBLIC  :: InputType                               
     TYPE(InputType_C)                          :: C_obj   
     REAL(KIND=C_DOUBLE) , ALLOCATABLE , TARGET :: In_X(:)   
     REAL    , DIMENSION(:) , ALLOCATABLE       :: X                    
     REAL    , DIMENSION(:) , ALLOCATABLE       :: Y                    
     REAL    , DIMENSION(:) , ALLOCATABLE       :: Z                    
     INTEGER , DIMENSION(:) , ALLOCATABLE       :: index
     INTEGER                                    :: Xlen                 
     INTEGER                                    :: Ylen                 
     INTEGER                                    :: Zlen                 
     INTEGER                                    :: indexlen
  END TYPE InputType     
  </code></pre>
  
  <p>I get the error:</p>
  
  <pre><code>REAL(KIND=C_DOUBLE) , ALLOCATABLE  , TARGET :: In_X(:)
                                            1
      Error: Attribute at (1) is not allowed in a TYPE definition
  </code></pre>
  
  <p>Is there a way to eliminate this error?</p>