IMPORT or C Binding bug?

Christopher D. Rickett crickett@lanl.gov
Thu Jun 28 21:28:00 GMT 2007


i don't think the problem has anything to do with C binding.  for example, 
the following simplified code behaves the same:

module pthreads
    implicit none
    private
    save

    integer, parameter :: my_kind = 4

    interface
!
!  This fails!
!
      integer(kind=my_kind) function pthread_cond_init()
         import :: my_kind
      end function pthread_cond_init

!
!  This works.
!
!      function pthread_cond_init()
!        import :: my_kind
!        integer(kind=my_kind) pthread_cond_init
!      end function pthread_cond_init
   end interface
end module pthreads


the first one fails with the following error messages:

kargl.f03:12.18:

      integer(kind=my_kind) function pthread_cond_init()
                  1
Error: Parameter 'my_kind' at (1) has not been declared or is a variable, 
which does not reduce to a constant expression
kargl.f03:13.14:

         import :: my_kind
              1
Error: IMPORT statement at (1) only permitted in an INTERFACE body
kargl.f03:14.8:

      end function pthread_cond_init
        1
Error: Expecting END INTERFACE statement at (1)


the second works just fine.

Chris

On Thu, 28 Jun 2007, Steve Kargl wrote:

> In trying to compile some real world code with Chris'
> ISO C Binding patch, I ran into the following code:
>
> module pthreads
>
>   use, intrinsic :: iso_c_binding
>
>   implicit none
>   private
>   save
>
>   type, bind( c) :: pthread_t
>      private
>      integer(kind=c_int), dimension(2) :: secret
>   end type pthread_t
>
>   interface
> !
> ! This works.
> !
>      type(pthread_t) function pthread_testcancel( ) bind(c)
>         import :: pthread_t
>      end function pthread_testcancel
> !
> !  This fails!
> !
> !      integer(kind=c_int) function pthread_cond_init(cond, attr) bind(c)
> !         import :: c_ptr, c_int
> !         type(c_ptr), value :: cond
> !         type(c_ptr), value :: attr
> !      end function pthread_cond_init
>
>      function pthread_cond_init(cond, attr) bind(c)
>         import :: c_ptr, c_int
>         integer(kind=c_int) pthread_cond_init
>         type(c_ptr), value :: cond
>         type(c_ptr), value :: attr
>      end function pthread_cond_init
>   end interface
> end module pthreads
>
> Should the code marked 'This fails!' actually compile?  Note that
> 'import(pthread_t)' works in the previous interface.  If I re-arrange
> the code as in the last interface, the 'import :: c_int' appears
> to correctly pick up the correct value.
> -- 
> Steve
>



More information about the Fortran mailing list