!  Properly, the "intent" should be "out", but if that declaration is used, the
!  program crashes.  This is a known bug of gfortran, bug 92621.
!  See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92621

program demo_main

   use, intrinsic :: iso_c_binding, only: C_LONG, C_DOUBLE
   implicit none

interface

   function demo ( array )  bind ( C, name="demo" )

      import
      implicit none

      integer (C_LONG) :: demo
      real (C_DOUBLE), dimension (:), allocatable, intent (inout) :: array

   end function demo

end interface

   integer (C_LONG) :: status
   real (C_DOUBLE), dimension (:), allocatable :: array

   status = demo ( array )

   if ( status == 0 ) then
      write (*, '( "size of array: ", I0 )' )  size (array)
      write (*, '( "bounds of array: ", I0, 2X, I0 )' )  lbound (array), ubound (array)
      write (*, '( "contents of array:", *(1X, F9.4) )' )  array
   else
      write (*, '( "C demo failed with status: ", I0 )' )  status
   end if

end program demo_main