[Bug fortran/84885] c_char bind length
sgk at troutmask dot apl.washington.edu
gcc-bugzilla@gcc.gnu.org
Fri Mar 16 17:12:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84885
--- Comment #6 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Fri, Mar 16, 2018 at 01:11:30PM +0000, mdblack98 at yahoo dot com wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84885
>
> --- Comment #5 from mdblack98 at yahoo dot com ---
> I've been using Fortran since 1980 so caps is natural to me :-)
> My concern is that if gfortran has supported the len>1 convention for many
> years than perhaps it should continue supporting it to prevent breaking code
> like ours which will take some major effort to rewrite.Consider it an
> "extension" to gfortran which apparently it was. Still fully 2018 compliant
> with this one little extension. Enable it via a switch if you want to.
First, gcc-bugzilla is probably not the appropriate forum
for learning nuances of BIND(C). I suggest posting your
questions to the comp.lang.fortran newsgroup or Stack Overflow.
I've quoted two difference standards. Both state
If the type is character, the length type parameter is
interoperable if and only if its value is one.
The above isn't a numbered constraint, so gfortran is not
obligated to tell a user that in the following
subroutine foo(c)
use, intrinsic iso_c_binding
character(len=1000, kind=c_char), bind(c) :: c
end subroutine foo
'c' is not interoperable. Perhaps, gfortran should issue
at least a warning. As long as a program does not try to
use 'c' in an interoperable manner, gfortran appears to
ignore the bind(c) attribute. If a program, however, uses
'c' in an interoperable manner, the user may get a result
he expects even though it technically violates the Fortran
standard.
Now, when you wrap the character statement in a derived type
subroutine foo(c)
use, intrinsic :: iso_c_binding
type, bind(c) :: bar
character(len=1000, kind=c_char) :: c
end type
type(bar) bah
bah%c = "123"
end subroutine foo
a numbered constraint comes into play. gfortran must tell
the user that 'c' in type 'bar' is not interoperable. I quoted
the relevant text already. From F2018 (and similar appears in
other versions of the standard)
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.
More information about the Gcc-bugs
mailing list