Strange behaviour when using type(*) and character(*) in GFortran

Hi @Carltoffel ,

I think that for making that sub interafce as general as possible, you need to make two slight changes:

  1. use class(*) instead of type(*) (hoping that you don’t actually use that variable in the procedure, but then why to even pass it in the first place… so I fear you actually do use it).
  2. make the useless var assumed rank, in order to work with both scalar/array entries.

This worked with gfortran trunk, ifort/ifx latest.

program main
   implicit none
   character(len = *), parameter :: not_used              = 'A very long, long, long, long string'
   character(len = 1), parameter :: not_used_chArray(115) = 'A very long, long, long, long string, but as an array'
   call sub(not_used, "123")
   call sub(not_used_chArray, "123")
contains
   subroutine sub(useless_var, print_this)
      class(*), intent(in)     :: useless_var(..)
      character(*), intent(in) :: print_this
      print *, "should be 123:  '", print_this, "' "
   end subroutine sub
end

I tested using type(*), and ifort/ifx actually give the expected output. Don’t know at this point if it is a gfortran bug there. Might need to wait someone else’s answer for that.

Hope this helps.

1 Like