https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84885
--- Comment #2 from mdblack98 at yahoo dot com --- I got what's below from Steve Lionel of the FORTRAN working group....With what he said you flat should NOT be able to say anything other than LEN=1 for c_char. Whether it's in a type block or not.So the question becomes how to do this...since this is likely to break a bit of FORTRAN code out in the wild...like ours....It would appear you can't put a char array of any kind of type block which we use for shared memory. From Steve: However, I don't see that Fortran 2018 has anything to do with this. The code you show does not conform to Fortran 2003, which was the first revision to have C interoperability. The issue is that in an interoperable type (a type declared with BIND(C)), any entity of type CHARACTER must have length 1, because C doesn't have the concept of character lengths. Instead you would make c here a 10-element array of single characters. It's ok outside of the type because you're not declaring something interoperable then. Similarly, a dummy argument to an interoperable procedure can't have a character length other than 1 up through Fortran 2008. In Fortran 2018, you're allowed to use CHARACTER(*), but that requires that the corresponding C code pass or accept a "C descriptor". That earlier versions of gcc allowed this to compile would be a bug in those older versions. ----------------------------------- Michael D. Black On Thursday, March 15, 2018, 11:42:40 AM CDT, kargl at gcc dot gnu.org <gcc-bugzi...@gcc.gnu.org> wrote: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84885 kargl at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED CC| |kargl at gcc dot gnu.org Resolution|--- |INVALID --- Comment #1 from kargl at gcc dot gnu.org --- (In reply to mdblack98 from comment #0) > subroutine foo(i,c) > use, intrinsic :: iso_c_binding, only: c_char > integer i > > type, bind(C) :: params_block > character(kind=c_char,len=10) :: c I see length of 10 here. > end type params_block > write(*,*) 'X',c,'Z' > end > > This program fails to compile with gcc 8.0.1 20180304 -- but only if the > character declaration is inside a type block > Compiles fine with pre 8.0 compilers > > gfortran -fPIC -g -c foo.f90 > foo.f90:6:42: > > character(kind=c_char,len=10) :: c > 1 > Error: Component 'c' of BIND(C) type at (1) must have length one From the F2018 standard, 18.3.2 Interoperability of intrinsic types Table 18.2 shows the interoperability between Fortran intrinsic types and C types. A Fortran intrinsic type with particular type parameter values is interoperable with a C type if the type and kind type parameter value are listed in the table on the same row as that C type. If the type is character, the length type parameter is interoperable if and only if its value is one. C1806 (R726) Each component of a derived type with the BIND attribute shall be a nonpointer, nonallocatable data component with interoperable type and type parameters. Your code is invalid, and the number constraint means that gfortran must tell you about it.