This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/84885] c_char bind length
- From: "kargl at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 15 Mar 2018 16:42:37 +0000
- Subject: [Bug fortran/84885] c_char bind length
- Auto-submitted: auto-generated
- References: <bug-84885-4@http.gcc.gnu.org/bugzilla/>
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.