Skip to content

Return type on pspinfo accessors

The Intel Fortran compiler produces an error when compiling the getter functions in interface_pspinfo_inc.F90 which return C strings. The functions are prototyped a'la

character(kind=c_char) function pspio_pspinfo_get_author(pspinfo) bind(c)

but the C function to which it is bound is prototyped as

const char * pspio_pspinfo_get_author(const pspio_pspinfo_t *pspinfo)

The Intel Fortran compiler is complaining because the Fortran interface to the C function is declared as returning a C char scalar; that return value is being passed as the first argument to the c_to_f_string() subroutine, which is prototyped such that the argument is expected to be an indeterminate-length array of C char scalars.

Other Fortran compilers likely overlook this since the Fortran ABI passes pointers anyway — the appropriate type is implicit, Intel wants it to be explicit.

Would it be more appropriate for the pspio_pspinfo_get_author() et al. functions to be declared with a Fortran interface of

type(c_ptr) function pspio_pspinfo_get_author(pspinfo) bind(c)

and that return value be passed not to c_to_f_string() but to c_to_f_string_ptr() in e.g.

character(len=256) function pspiof_pspinfo_get_author(pspinfo) result(author)
  type(pspiof_pspinfo_t), intent(in) :: pspinfo
 
  call c_to_f_string_ptr(pspio_pspinfo_get_author(pspinfo%ptr), author)

end function pspiof_pspinfo_get_author

Making those two changes the Intel Fortran compiler no longer complains about the typing.